feat: add connect_with_socket() for custom transports#4212
Closed
airhorns wants to merge 1 commit intolaunchbadge:mainfrom
Closed
feat: add connect_with_socket() for custom transports#4212airhorns wants to merge 1 commit intolaunchbadge:mainfrom
airhorns wants to merge 1 commit intolaunchbadge:mainfrom
Conversation
b68895c to
601227c
Compare
Add the ability to establish MySQL and PostgreSQL connections over pre-connected sockets, enabling custom transports such as in-memory pipes, simulation frameworks (e.g. turmoil for deterministic simulation testing), SSH tunnels, or SOCKS proxies. Changes: - Add `net::connect_with()` in sqlx-core as the analog of `connect_tcp` and `connect_uds` for pre-established sockets - Add `MySqlConnectOptions::connect_with_socket()` and `MySqlConnection::connect_with_socket()` for MySQL - Add `PgConnectOptions::connect_with_socket()` and `PgConnection::connect_with_socket()` for PostgreSQL - Re-export `Socket` trait and `connect_with` from top-level `sqlx::net` - Refactor MySQL post-connect init into shared `after_connect()` to avoid duplication between `connect()` and `connect_with_socket()` The Socket trait was already public; these changes simply expose a way to pass a pre-connected Socket into the connection establishment flow that was previously only reachable through connect_tcp/connect_uds.
601227c to
cf6ee57
Compare
Collaborator
|
Duplicate of #4187 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I want to make use of the
turmoilcrate to implement deterministic simulation testing for a system I'm working on that makes use of sqlx. Turmoil works by virtualizing all the networking that different elements of a system do so it can inject faults, like in my app's connection to MySQL!sqlxdoesn't need to know anything about turmoil, but before this change, it wasn't possible to inject in turmoil's special socket implementation that lets it do its thing. It's weird to say, but sqlx "hardcoded" the use of tokio's socket.To let folks like me inject alternative implementations of the
Sockettrait, we need a new high level public function for connecting using our own sockets! This adds that. The same api also would let folks inject sockets that do weird other transport stuff, like tunnels or proxies.Changes:
net::connect_with()in sqlx-core as the analog ofconnect_tcpand
connect_udsfor pre-established socketsMySqlConnectOptions::connect_with_socket()andMySqlConnection::connect_with_socket()for MySQLPgConnectOptions::connect_with_socket()andPgConnection::connect_with_socket()for PostgreSQLSockettrait andconnect_withfrom top-levelsqlx::netafter_connect()toavoid duplication between
connect()andconnect_with_socket()The Socket trait was already public; these changes simply expose a way to pass a pre-connected Socket into the connection establishment flow that was previously only reachable through connect_tcp/connect_uds.
Does your PR solve an issue?
No, no open issue
Is this a breaking change?
No, no breaking change