Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/src/main/paradox/server-side/http2.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ connection with `FLOW_CONTROL_ERROR`, as required by [RFC 9113 section 6.9.2](ht
An overflow caused by a stream-specific `WINDOW_UPDATE` still affects only that stream. These rules also
apply to the HTTP/2 client and do not change HTTP/1.1 fallback behavior.

On receive, both the application data and any padding in a DATA frame count toward its HTTP/2 flow-control
windows. Padding and its length field are discarded before delivering the entity and do not count toward
the HTTP Content-Length. Discarded padding can release receive credit even when no entity bytes have been consumed.
See [RFC 9113 §6.1](https://www.rfc-editor.org/rfc/rfc9113.html#section-6.1).

## Limiting the lifetime of connections

Long-lived HTTP/2 connections, for example those used by gRPC, can lead to an uneven load distribution across
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,28 @@ private[http] object FrameEvent {
lastStreamId: Int, errorCode: ErrorCode, debug: ByteString = ByteString.empty) extends FrameEvent {
override def toString: String = s"GoAwayFrame($lastStreamId,$errorCode,debug:<hidden>)"
}
sealed trait DataFrameEvent extends StreamFrameEvent { self: Product =>
def endStream: Boolean
def payload: ByteString
def paddingSize: Int = 0
def sizeInWindow: Int
final override def frameTypeName: String = "DataFrame"
}

final case class DataFrame(
streamId: Int,
endStream: Boolean,
payload: ByteString) extends StreamFrameEvent {

/**
* The amount of bytes this frame consumes of a window. According to RFC 7540, 6.9.1:
*
* For flow-control calculations, the 9-octet frame header is not
* counted.
*
* That means this size amounts to data size + padding size field + padding.
*/
def sizeInWindow: Int = payload.size // FIXME: take padding size into account, #1313
payload: ByteString) extends DataFrameEvent {
override def sizeInWindow: Int = payload.size
}

/** Received DATA with its padding stripped from the entity, but not from flow control (RFC 9113 §6.1). */
final case class PaddedDataFrame(
streamId: Int,
endStream: Boolean,
payload: ByteString,
override val paddingSize: Int) extends DataFrameEvent {
override def sizeInWindow: Int = payload.size + paddingSize // includes the Pad Length field
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ private[http2] object FrameLogger {
LogEntry(streamId, "HEAD", prioInfo + hex(payload), flag(endStream, "ES"), flag(endHeaders, "EH"))
case ContinuationFrame(streamId, endHeaders, payload) =>
LogEntry(streamId, "CONT", hex(payload), flag(endHeaders, "EH"))
case DataFrame(streamId, endStream, payload) =>
LogEntry(streamId, "DATA", hex(payload), flag(endStream, "ES"))
case data: DataFrameEvent =>
LogEntry(data.streamId, "DATA", hex(data.payload), flag(data.endStream, "ES"))

case GoAwayFrame(lastStreamId, errorCode, debug) =>
LogEntry(0, "GOAY", s"lastStreamId = $lastStreamId, errorCode = $errorCode, debug = ${debug.utf8String}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,8 @@ private[http] object Http2Blueprint {
* Not a real `frameTypeName`, so it never matches one directly: [[frameCost]] recognises it and charges every DATA
* frame that carries no payload.
*
* Such a frame consumes no flow-control window, so unlike a data-carrying one its number is not bounded by flow
* control at all and a peer can send them continuously. Data-carrying frames are deliberately not covered, because
* throttling those would throttle legitimate throughput along with them.
* DATA without either content or padding consumes no flow-control window. Data-carrying frames are deliberately not
* covered, because throttling those would throttle legitimate throughput along with them.
*/
private[http2] val EmptyDataFrameThrottleName = "EmptyDataFrame"

Expand All @@ -294,11 +293,11 @@ private[http] object Http2Blueprint {
private[http2] def frameCost(frameTypesForThrottle: Set[String], event: FrameEvent): Int =
if (frameTypesForThrottle.contains(event.frameTypeName)) 1
else event match {
case d: DataFrame if d.payload.isEmpty && isThrottledEmptyDataFrame(frameTypesForThrottle, d) => 1
case _ => 0
case d: DataFrameEvent if d.payload.isEmpty && isThrottledEmptyDataFrame(frameTypesForThrottle, d) => 1
case _ => 0
}

private def isThrottledEmptyDataFrame(frameTypesForThrottle: Set[String], frame: DataFrame): Boolean =
private def isThrottledEmptyDataFrame(frameTypesForThrottle: Set[String], frame: DataFrameEvent): Boolean =
frameTypesForThrottle.contains(EmptyDataFrameThrottleName) ||
(!frame.endStream && frameTypesForThrottle.contains(EmptyDataFrameNoEndStreamThrottleName))

Expand Down
Loading