Postgres: Move io to background task. #3891
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.
This PR moves all the io in the postgres driver to a background task. This should fix some long standing issues with cancellation safety and unblock/allow features like query pipelining, CopyBoth mode (#2924) and the ability to cancel queries. This also simplifies the dropping of
PgTransaction
,PgCopyIn
andPgListener
. There is still some work to do to increase performance but that's out of the scope of this PR.Notable changes:
SocketExt
: An extension trait forSocket
which has async methods for reading, writing, flushing and closing.BufferedSocket
now has poll methods for reading messages.BufferedSocket
has aSink<&[u8]>
impl to send bytes.Pipe
is added; a temporary stream of responses from the background worker.Worker
is added; the background worker that handles all the io.ReadyForQuery
messages because thewait_until_ready
mechanism is removed.Shared
is added; a shared structure between the connection and background worker.This is a pretty big change that touches a lot in the postgres driver. I've added a lot of comments to explain my thinking, if there is anything else I can do to make this easier lmk.
Does your PR solve an issue?
TODO
Is this a breaking change?
No, this PR only has breaking changes in sqlx-core which is semver exempt. One unit test had to be changed for
PgListener
because the buffering mechanism is changed. I don't think that makes this a breaking change and I don't think Hyrum's law applies here.