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.
[py-core] Async Connection Foundation #288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[py-core] Async Connection Foundation #288
Changes from all commits
d740d6eb41bf3f070a741b0b732f6a75af12b152dd7b40950280ad92File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
python_loggerbridge only covers the synchronous part ofconnect.scoped_tracing_bridgereturns a thread-localDefaultGuard, and_guardis dropped the momentconnectreturns — but the actual TCP+TLS+login handshake runs later, inside thefuture_into_pyblock, on a Tokio worker thread. So every event in that block bypasses the caller's logger: theconnection establishedline and, more importantly, the connect-failure error frommap_tds_error("connect", ...)(line 121) — which is exactly the log someone who bothered to pass apython_loggerwould most want.The sync
PyCoreConnection::newdoesn't hit this because it drives the handshake withruntime.block_on(...)inline, under the guard, on the same thread.Can we move the bridge into the async block (hand the
Arc<Py<PyAny>>into the future andset_defaultthere), or — if capturing only the prelude is intentional for this foundation — document that per-callpython_loggerdoesn't cover the async handshake? As written, passing a logger silently drops the failure diagnostics.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocking: this bridge does not cover any of the async work, including the connect-failure log.
scoped_tracing_bridgecallstracing::subscriber::set_default, which is thread-local and is undone when the guard drops at the end ofconnect. Thefuture_into_pybody runs later, on a Tokio worker thread. So of the events inconnect, the Python logger receives only the four synchronous pre-flightinfo!lines, and never receives:"connection established"(L123)map_tds_error("connect", ...)'stracing::error!(L50) - the handshake-failure diagnostic, which is the whole reason a caller passes a loggerThis is the opposite of the sync path it is modeled on:
PyCoreConnection::newusesruntime.block_onon the same thread, so itstracing::error!("Failed to connect to SQL Server: {}", e)is inside the guard. Separately,close/commit/rollback/cursortake no logger and are never bridged at all, so the connection is unlogged for its entire lifetime afterconnectreturns.Concrete fix - propagate a
Dispatchacross the await point instead of a thread-local guard. Add alongside the existing helpers inpython_logger_adapter.rs:then here:
DispatchisClone + Send + Sync, so it can also be stored on the pyclass and reused byclose/commit/rollback- which is what makes the parameter actually useful.If that is too much for this PR, I would accept: drop the
python_loggerparam for now, or keep it and (a) state the limitation in the Python-visible docstring rather than only a code comment, and (b) file a follow-up work item. What I would rather not ship is apython_logger=that silently swallows the failure path.Supporting point: there is no test that passes a
python_logger. A test asserting which records reachpy_core_logfor both a successful and a failed connect would have caught this, and is the right regression guard for whichever fix you pick.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
"initiating async connection"is immediately followed by"extracting client context"at the same level - the first adds nothing. Also, the sync path usesdebug!for the dict conversion;info!for every step is chatty on a per-connection path.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two
info!lines fire back to back with no work between them (initiating async connection, thenextracting client context). Drop the first — it's noise.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: negative values raise
OverflowErrorhere, butmssql_python.Connection.timeout's setter raisesValueError("Timeout cannot be negative")(andTypeErrorfor non-int).test_timeout_setter_rejects_negativelocksOverflowErrorin.If the Python wrapper will always sit on top, this is fine - but worth a one-line note in the docstring so nobody is surprised when the two surfaces disagree. Otherwise take
i64and raiseValueErrorexplicitly for parity.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
connect()returnsErron handshake failure and only ever builds the instance withSome(client), so there's no public path to an instance that starts out closed. The "or ifconnect()never produced a live client" clause describes a state this API can't reach — trim it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
cursor(),commit(), androllback()all raiseRuntimeError("Connection is closed"), butasync with closed_conn:succeeds and then no-ops on exit. Suggest matching the rest of the surface:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: this docstring is now a fragment that says neither what
cursor()returns nor that it raisesRuntimeErrorwhen the connection is closed - both of which are contract that shows up in Pythonhelp(). Worth one line back:Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.