refactor: iterate login response tokens directly#1759
Open
arthurschreiber wants to merge 2 commits into
Open
Conversation
Instead of wrapping the `StreamParser.parseTokens` async generator back into a `Readable`/`EventEmitter` via the token stream parser just to wait for its `end` event, the login response handling methods now iterate the generator directly through a shared `processTokens` helper. This also improves error behavior: a parser error during login previously fired as an `error` event on an internal `Readable` that had no listener - crashing the process - while the `end` event the login methods were waiting for never fired. Parser errors now simply reject and surface as a clean connection failure. The token stream parser is still used by the request execution states; those move to direct iteration in a follow-up. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The server responds to the Login7 message with data that is not a valid token stream. Previously, the parser error fired as an `error` event on an internal `Readable` that had no listener - an uncaught exception - while the connect callback only fired once the connect timeout expired, with a misleading timeout error. With direct token iteration, the parser error surfaces as a clean, immediate connection failure. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ReviewNice, focused refactor — replacing the Correctness
Style / scope
Test coverage
Performance / security
Overall this is a solid, well-scoped refactor with a legitimate bug fix. Main suggestion is adding a regression test for the crash scenario described in the PR body. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1759 +/- ##
==========================================
+ Coverage 79.88% 80.89% +1.00%
==========================================
Files 90 90
Lines 4887 4893 +6
Branches 924 926 +2
==========================================
+ Hits 3904 3958 +54
+ Misses 694 639 -55
- Partials 289 296 +7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
The four login-path response handlers (
performSentLogin7WithStandardLogin,...WithNTLMLogin,...WithFedAuth, andperformLoggedInSendingInitialSql) consumed their response tokens by wrapping theStreamParser.parseTokensasync generator back into aReadable/EventEmitter(viacreateTokenStreamParser) just toawait once(parser, 'end')while token dispatch happened throughdataevents.They now iterate the generator directly through a small shared
processTokens(message, handler, signalAborted)helper: pull a token, dispatch it to the handler, until the message ends or the abort promise rejects.Besides removing a layer of indirection, this fixes a latent error-handling hole: a parser error during login previously fired as an
errorevent on the internalReadable— which had noerrorlistener, crashing the process — while theendevent the login methods were waiting on never fired. With direct iteration, a parser error simply rejects and surfaces as a clean connection failure through the existing error handling ininitialiseConnection. A regression test covers this: on the old code it reproduces the uncaught exception, followed by the connect callback only firing at the connect timeout with a misleadingFailed to connecterror; on this branch the parser error surfaces immediately.The token stream parser wrapper is still used by the
SENT_CLIENT_REQUEST/SENT_ATTENTIONstates; those move to direct iteration (and the wrapper gets deleted) in the upcomingmakeRequestrefactor.Performance: connect-path only, and measured as neutral —
benchmarks/connection/open.jsbefore/after (median of 3 runs, local SQL Server): 32.2/37.1 conn/s on master vs 32.3/36.9 conn/s with this change (n=10/100).🤖 Generated with Claude Code