diff --git a/packages/libsql-client/src/__tests__/config.test.ts b/packages/libsql-client/src/__tests__/config.test.ts index 30fd41f..9c86ae5 100644 --- a/packages/libsql-client/src/__tests__/config.test.ts +++ b/packages/libsql-client/src/__tests__/config.test.ts @@ -232,3 +232,40 @@ describe("expandConfig - parsing of valid arguments", () => { }); } }); + +describe("expandConfig - concurrency", () => { + const cases = [ + { + name: "default", + config: { url: "file://local.db" }, + concurrency: 20, + }, + { + name: "explicit limit", + config: { url: "file://local.db", concurrency: 42 }, + concurrency: 42, + }, + { + name: "zero disables the limit", + config: { url: "file://local.db", concurrency: 0 }, + concurrency: 0, + }, + { + name: "negative clamps to zero", + config: { url: "file://local.db", concurrency: -5 }, + concurrency: 0, + }, + { + name: "in-memory zero disables the limit", + config: { url: ":memory:", concurrency: 0 }, + concurrency: 0, + }, + ]; + for (const { name, config, concurrency } of cases) { + test(name, () => { + expect(expandConfig(config, false).concurrency).toEqual( + concurrency, + ); + }); + } +}); diff --git a/packages/libsql-client/src/sqlite3.ts b/packages/libsql-client/src/sqlite3.ts index 3044da3..be852dc 100644 --- a/packages/libsql-client/src/sqlite3.ts +++ b/packages/libsql-client/src/sqlite3.ts @@ -82,8 +82,12 @@ export function _createClient(config: ExpandedConfig): Client { // second connection would be a second, empty database rather than another // way into the same one. Each connection to an embedded replica carries // its own sync state. Both are therefore single-connection databases. + // A concurrency of 0 means no limit, matching the remote clients, whose + // promise-limit semaphore treats a falsy limit as pass-through. const maxConnections = - isInMemory || config.syncUrl ? 1 : Math.max(1, config.concurrency); + isInMemory || config.syncUrl + ? 1 + : Math.max(1, config.concurrency || Infinity); const options = { authToken: config.authToken, diff --git a/packages/libsql-core/src/config.ts b/packages/libsql-core/src/config.ts index 44dd7bf..cda770c 100644 --- a/packages/libsql-core/src/config.ts +++ b/packages/libsql-core/src/config.ts @@ -53,7 +53,7 @@ export function expandConfig( let { url, authToken, tls, intMode, concurrency } = config; // fill simple defaults right here - concurrency = Math.max(0, concurrency || 20); + concurrency = Math.max(0, concurrency ?? 20); intMode ??= "number"; let connectionQueryParams: string[] = []; // recognized query parameters which we sanitize through white list of valid key-value pairs