Skip to content

Commit adb9d45

Browse files
committed
fix(ws): ask for a stateless gateway connection with websocketStateless, not websocketConcurrent
websocketConcurrent only sends queries without waiting. websocketStateless sends auth.stateless, so the gateway runs each query on its own server connection; without it the gateway keeps one for the socket, with its state.
1 parent fce3980 commit adb9d45

4 files changed

Lines changed: 11 additions & 7 deletions

File tree

‎src/drivers/connection-ws.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ 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 }
124+
if (this.config.websocketStateless) {
125+
// tells the gateway to run each request on its own connection, instead of in order on one kept for the socket
126+
ioOpts.auth = { ...(ioOpts.auth as object), stateless: true }
127127
}
128128
const reconnect = this.config.websocketReconnect !== false
129129
if (!reconnect) {

‎src/drivers/types.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,10 @@ 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 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 */
117+
/** Send websocket queries as soon as they are issued instead of one at a time, default: false. Their order is not guaranteed */
118118
websocketConcurrent?: boolean
119+
/** Ask the gateway to run each websocket query on its own server connection, in parallel, default: false. No state (transactions, temp tables, pragmas) is kept between queries; without it the gateway keeps one server connection for the socket and runs its queries in order */
120+
websocketStateless?: boolean
119121

120122
/** Optional identifier used for verbose logging */
121123
clientid?: string

‎src/drivers/utilities.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ export function parseconnectionstring(connectionstring: string): SQLiteCloudConf
272272
websocketMaxAttachments: options.websocket_max_attachments ? parseWebsocketMaxAttachments(options.websocket_max_attachments) : undefined,
273273
websocketReconnect: options.websocket_reconnect ? parseBoolean(options.websocket_reconnect) : undefined,
274274
websocketConcurrent: options.websocket_concurrent ? parseBoolean(options.websocket_concurrent) : undefined,
275+
websocketStateless: options.websocket_stateless ? parseBoolean(options.websocket_stateless) : undefined,
275276
verbose: options.verbose ? parseBoolean(options.verbose) : undefined
276277
}
277278

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

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

518-
it('should tell the gateway the connection is concurrent', () => {
518+
it('should ask the gateway for a stateless connection only with websocketStateless', () => {
519519
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 })
520+
expect(((io as jest.MockedFunction<typeof io>).mock.calls[0]?.[1] as any).auth).toEqual({ token: 'secret' })
521+
connectMockedSocket({ websocketStateless: true })
522+
expect(((io as jest.MockedFunction<typeof io>).mock.calls[1]?.[1] as any).auth).toEqual({ token: 'secret', stateless: true })
522523
})
523524

524525
it('should send commands without waiting for the previous ones with websocketConcurrent', () => {

0 commit comments

Comments
 (0)