Repository navigation
Preserve the final HTTP/2 DATA frame during graceful shutdown #1455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,10 @@ private[http2] trait Http2Multiplexer { | |
|
|
||
| def maxBytesToBufferPerSubstream: Int | ||
|
|
||
| /** | ||
| * True only when no frames remain buffered and no state transition is in progress. | ||
| * A stream can close synchronously while its final frame is still being handed downstream. | ||
| */ | ||
| def hasFlushedAllData: Boolean | ||
| } | ||
|
|
||
|
|
@@ -143,7 +147,13 @@ private[http2] trait Http2MultiplexerSupport { logic: GraphStageLogic with Stage | |
|
|
||
| private var _state: MultiplexerState = Idle | ||
|
|
||
| def hasFlushedAllData: Boolean = allDataFlushed(_state) | ||
| // A transition can close the last stream before its final frame is pushed, e.g. when `sendDataFrame` pulls the | ||
| // last DATA frame of a stream. Don't report all data as flushed until the transition is done; `updateState` calls | ||
| // `onAllDataFlushed` afterwards if the new state has flushed everything. | ||
| // This depth only guards the flushed-data observation during synchronous callbacks. It does not | ||
| // make nested state transitions safe: the outer transition still owns the resulting state. | ||
| private var transitionDepth = 0 | ||
| def hasFlushedAllData: Boolean = transitionDepth == 0 && allDataFlushed(_state) | ||
| private def allDataFlushed(state: MultiplexerState): Boolean = (state eq WaitingForData) || (state eq Idle) | ||
|
|
||
| private val controlFrameBuffer: mutable.Queue[FrameEvent] = new mutable.Queue[FrameEvent] | ||
|
|
@@ -158,7 +168,10 @@ private[http2] trait Http2MultiplexerSupport { logic: GraphStageLogic with Stage | |
|
|
||
| private def updateState(transition: MultiplexerState => MultiplexerState): Unit = { | ||
| val oldState = _state | ||
| val newState = transition(_state) | ||
| transitionDepth += 1 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A depth counter suggests nested |
||
| val newState = | ||
| try transition(_state) | ||
| finally transitionDepth -= 1 | ||
| _state = newState | ||
|
|
||
| if (isDebugEnabled && newState.name != oldState.name) recordStateChange(oldState.name, newState.name) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The underlying issue is that
Http2StreamHandlingcallsonAllStreamsClosedsynchronously from inside a multiplexer transition. GatinghasFlushedAllDataworks, but any other re-entrant logic incompleteIfDonestill runs mid-transition. Was deferringonAllStreamsCloseduntil the transition completes considered (similar to howdeferredStreamToEnqueuealready defersenqueueOutStream)? If you prefer to keep this approach, could the changed contract ("returns false while a transition is in progress") also be documented on the trait declaration at line 50, since that's whatHttp2Demuxcodes against?