httpsession: simplify queue processing logic #48109
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently,
HttpSession
sends messages to clients while in either theHolding
orSendingQueue
states. Sending during theHolding
state happens when the session is idle and a message is published to it. Sending during theSendingQueue
state happens when the session starts sending messages that had queued up while it was in some state other thanHolding
orSendingQueue
. TheSendingQueue
state can be thought of as a sort of catch-up state.Having two distinct states for sending messages makes the code hard to follow, and upon review there doesn't seem to be much difference between the way the two states are meant to work. Notably, if the client can't be written to while in
Holding
state, a queue of messages still builds up. If anything, having two states for the same thing has resulted in subtle inconsistencies and bugs, especially after we introduced async message filters which made sending non-atomic. This PR consolidates onSendingQueue
as the one state for sending messages, and fixes a few related issues.The changes:
Holding
state is now only for idleness. If a message is published to the session while in that state, it switches toSendingQueue
to process the message (as well as any others that arrive during processing). After all the messages in the queue have been processed, the state switches back toHolding
.Holding
state, but not theSendingQueue
state, which was probably not intended.SendingQueue
state (meaning, backpressure while inHolding
state broke these timers). This is now done insendQueueDone()
, with care taken to not reset the timeouts if they are already active.Closing
, but if the message is dropped then the state gets stuck asSendingQueue
. Now we callsendQueueDone()
after processing all messages, just like stream mode, which ensures the state gets set back toHolding
so another message can be accepted.Testing: manually tested all the changed code paths.