Repository navigation
Conversation
On the WebSocket transport a query waits for the socket.io ack of 'GET /v2/weblite/sql'. When the socket disconnected mid-query the ack never fired and the error was only sent to the connect callback, which had already run, so the query promise stayed pending forever. - track the commands waiting for an ack and fail them with the disconnect/connection error when the socket goes away or close() is called - report the connect callback only once, for the outcome of the connection attempt - honour config.timeout on the WebSocket transport too Fixes #283
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #284 +/- ##
==========================================
+ Coverage 85.23% 85.71% +0.47%
==========================================
Files 11 11
Lines 1131 1155 +24
Branches 374 375 +1
==========================================
+ Hits 964 990 +26
+ Misses 167 153 -14
- Partials 0 12 +12 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Fixes #283
Problem
On the WebSocket transport,
transportCommandswaits for the socket.io ack ofGET /v2/weblite/sql. If the socket disconnects while a query is in flight (for example when the gateway closes the connection because the request exceeds itsmaxHttpBufferSize, or on aping timeout):disconnecthandler only calls the connect callback, which already ran onconnect, so the error is logged (SQLiteCloudConnection.connect - error connecting … Disconnected) but never reaches the command;close()clears the operations queue, so nothing else settles it;The result is a
db.sql(...)promise that never resolves nor rejects.A side effect of calling the connect callback a second time is that the base
connect()wrapper calls the queue'sdonetwice, andDatabasereceives a second callback for the same connection.Fix (
src/drivers/connection-ws.ts)pendingCommandsuntil its ack arrives. Its callback is guarded so it runs exactly once (response, timeout or connection loss).disconnect,connect_erroranderrorclose the socket and fail every pending command with the same error the connect callback used to receive (ERR_CONNECTION_ENDEDwith the socket.io reason ascause, the attachment limit error, etc.).close()fails pending commands withERR_CONNECTION_CLOSED.config.timeout(default 300 s) now applies to WebSocket requests too: when it elapses the command fails withERR_CONNECTION_TIMEOUTand a late ack is ignored. The connection stays open, since the gateway handles every request independently.The request size limit itself is a gateway configuration and is out of scope here: with this change, whatever the limit is, the driver reports an error instead of hanging.
Testing
New unit tests in
test/connection-ws-unit.test.ts(mocked socket.io):ERR_CONNECTION_ENDEDon disconnect, and the connect callback is not called again;connectis still reported to the connect callback;close()fails the command in flight;timeoutand a late response is ignored;Three of these fail on
mainand pass with the fix.Manual check against the staging gateway, sending
SELECT length(X'…')payloads above its message size limit:mainERR_CONNECTION_ENDED(transport error) in ~1.8 sERR_CONNECTION_ENDED(transport error) in ~2.8 sERR_CONNECTION_TIMEOUT(test config timeout 10 s)connection-ws,blob-transport,database,statementandutilitiestest suites pass.