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.
Abstract
When parsing, clients can receive different indications that tell the binding to retry parsing ex: state mismatch, etc; There's also the case when a connection is 'stale' (the socket is open but EdgeDB sent an
ErrorResponse
with the codeIdleSessionTimeoutError
), when the binding attempts to parse in this state, it will read the session timeout error and reconnect. The problem though is theParseAsync
method didn't really have the correct state for handling reconnection, the underlying protocol providers' phase was not correctly reset causing theReconnectAsync
function to end early on the serversAuthentication
message. Connection flow should look like the following:In this example,
Parse
should be sent after the binding receivesReadyForCommand
which indicated that theConnection
phase is complete, but in actuality the binding thought it was already in theCommand
phase, so this is what the flow actually looked like:After sending the
Parse
andSync
, it would wait forIProtocolProvider.Phase
to beCommand
, indicating that command actions can be sent, but since this is never reset, it completes on the first message.Ultimately, this edge case caused the following exception in apps:
which is generally misleading to the actual cause.
Summary
This PR fixes this issue by resetting the protocol providers' state whenever trying to run
ConnectInternalAsync
, and properly waits for the phase to switch toCommand
before returning out ofConnectAsync
, causing any command phase actions to wait for this to be preformed.