Ensure a single handler manages channel's auto-read #528
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.
PullAllResponseHandler
is responsible for receiving a stream of records. Stream might be very large and handler tries to not fetch if fully into memory. It applies a network-level backpressure by disabling/enabling auto-read property of the underlying Netty channel. This property tells channel to not read from the network. Auto-read is disabled when number of queued records goes beyond the threshold.Management of auto-read turned out to be problematic for nested queries within a single transaction. Nested queries result in multiple
PullAllResponseHandler
s being added to the queue of handlers. They will try to manage auto-read concurrently and can sometimes disable it completely. Callers would then be blocked and unable to proceed. This is not a problem forSession#run()
because every such call ensures there was a logical SYNC and the previous query has completed and its result is buffered.This PR fixes a problem by making only a single installed handler manage the channel's auto-read property. Making sure there only exists a single such handler is the responsibility of
InboundMessageDispatcher
. Auto-read is enabled when new auto-read managing handler is installed. Previous such handler is disabled.Also renamed
InboundMessageDispatcher#queue()
toInboundMessageDispatcher#enqueue()
.Fixes neo4j/neo4j#12033