Skip to content

Commit fce3980

Browse files
committed
fix(ws): tell the gateway when queries are concurrent
With websocketConcurrent the handshake sends auth.concurrent, so the gateway runs each request on its own connection instead of in order on one kept for the socket.
1 parent 332c911 commit fce3980

4 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sqlitecloud/drivers",
3-
"version": "1.0.1031",
3+
"version": "1.0.1032",
44
"description": "SQLiteCloud drivers for Typescript/Javascript in edge, web and node clients",
55
"main": "./lib/index.js",
66
"types": "./lib/index.d.ts",

‎src/drivers/connection-ws.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ export class SQLiteCloudWebsocketConnection extends SQLiteCloudConnection {
121121
if (authToken) {
122122
ioOpts.auth = { token: authToken }
123123
}
124+
if (this.config.websocketConcurrent) {
125+
// tells the gateway to run each request on its own, instead of in order on one connection kept for the socket
126+
ioOpts.auth = { ...(ioOpts.auth as object), concurrent: true }
127+
}
124128
const reconnect = this.config.websocketReconnect !== false
125129
if (!reconnect) {
126130
ioOpts.reconnection = false

‎src/drivers/types.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export interface SQLiteCloudConfig {
114114
websocketMaxAttachments?: number
115115
/** Reconnect the websocket after it drops, default: true. Queries in flight when it drops fail, later queries wait for the new connection */
116116
websocketReconnect?: boolean
117-
/** Send websocket queries as soon as they are issued instead of one at a time, default: false. The gateway runs them independently, so their order is not guaranteed */
117+
/** Send websocket queries as soon as they are issued instead of one at a time, default: false. The gateway then runs each query on its own connection: they may complete in any order, and no state (transactions, temp tables, pragmas) is kept between them */
118118
websocketConcurrent?: boolean
119119

120120
/** Optional identifier used for verbose logging */

‎test/connection-ws-unit.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,12 @@ describe('websocket transport helpers', () => {
515515
expect(socket.emit).toHaveBeenCalledTimes(2)
516516
})
517517

518+
it('should tell the gateway the connection is concurrent', () => {
519+
connectMockedSocket({ websocketConcurrent: true })
520+
const options = (io as jest.MockedFunction<typeof io>).mock.calls[0]?.[1] as any
521+
expect(options.auth).toEqual({ token: 'secret', concurrent: true })
522+
})
523+
518524
it('should send commands without waiting for the previous ones with websocketConcurrent', () => {
519525
const { connection, socket } = connectMockedSocket({ websocketConcurrent: true })
520526
connection.operations = new OperationsQueue()

0 commit comments

Comments
 (0)