Better handling extended protocol messages in the event of busy pool #155
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.
Let's imagine a Pgcat instance with single pool containing a single instance. The pool is fully occupied and all available connections are fully booked.
A client comes in, it connects and is now sitting idle in the external loop https://github.com/levkk/pgcat/blob/main/src/client.rs#L573
The client attempts to perform an extended protocol query. So first thing it does is send a
Pmessage. We try to grab a connection from the pool here but we fail. This failure sends us to this branch that ends withcontinue. ThePmessage never got buffered because we buffer message in the inner loop here. Subsequent extended protocol messages meet similar fate and now the client sends a syncSmessage, This one manages to break through, so we are able to grab a connection and we enter the inner loop (The transaction loop) but we arrived here without any of the previous messages being buffered so we end up with errors likeERROR: unnamed prepared statement does not existorERROR: portal "" does not exist. This does not affect clients that are already in the inner loop and have a server connection allocated.This change allows us to buffer the extended protocol message early without even checking out a connection from the pool. The actual checkout will be performed when the
Smessage arrives, at this point, we are guaranteed to have all messages buffered and have a client on the other end expecting a response. We can respond withSystemError: Failed to get a connection from the Poolor execute the query.