Don't reuse closed or mismatched MariaDB clients
grabMariaDBClient reused global.MARIADB_CLIENT whenever the requested config matched global.CONFIG. It never checked that the client was made from that config or was still open. init() sets global.CONFIG before creating the client, so a re-init after a close, or a config change, got back a closed or wrong client. - Remember the cache key each client was created with, and compare that - Wrapping close() drops the client from the cache and unsets global.MARIADB_CLIENT, so the next grab or ensureInit makes a new one - resolveClient goes through grabMariaDBClient instead of repeating the global.CONFIG comparison - Remove the queue test's workaround for this Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+3
-13
@@ -52,20 +52,10 @@ describe.skipIf(!TEST_DB)("Queue tables", () => {
|
||||
const createDBSchema = (await import("../src/lib/schema/create-db-schema")).default;
|
||||
const appendDefaults = (await import("../src/utils/append-default-fields-to-db-schema")).default;
|
||||
|
||||
/**
|
||||
* The test container uses a self-signed certificate. `db_config` gives
|
||||
* this file its own client, since other test files close theirs. The
|
||||
* client is created before `global.CONFIG` changes, so the previous
|
||||
* file's closed global client isn't reused.
|
||||
*/
|
||||
const config = {
|
||||
db_name: TEST_DB!,
|
||||
ssl_reject_unauthorized: false,
|
||||
db_config: { max: 10 },
|
||||
};
|
||||
setMariaDBClient({ config });
|
||||
global.CONFIG = config;
|
||||
// The test container uses a self-signed certificate
|
||||
global.CONFIG = { db_name: TEST_DB!, ssl_reject_unauthorized: false };
|
||||
global.DB_SCHEMA = schema;
|
||||
setMariaDBClient({ config: global.CONFIG });
|
||||
|
||||
DB = (await import("../src/index")).default;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user