Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

slonik

Package Overview
Dependencies
Maintainers
1
Versions
396
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slonik - npm Package Compare versions

Comparing version 43.0.4 to 43.0.5

22

dist/factories/createConnectionPool.js

@@ -32,3 +32,3 @@ "use strict";

try {
await Promise.all(waitingClients.map((waitingClient) => waitingClient.promise));
await Promise.all(waitingClients.map((waitingClient) => waitingClient.deferred.promise));
}

@@ -70,3 +70,3 @@ catch (error) {

connection.acquire();
waitingClient.resolve(connection);
waitingClient.deferred.resolve(connection);
};

@@ -83,3 +83,3 @@ connection.on('release', onRelease);

// eslint-disable-next-line promise/prefer-await-to-then
acquire().then(waitingClient.resolve, waitingClient.reject);
acquire().then(waitingClient.deferred.resolve, waitingClient.deferred.reject);
};

@@ -93,8 +93,18 @@ connection.on('destroy', onDestroy);

else {
const waitingClient = (0, defer_1.defer)();
waitingClients.push(waitingClient);
const deferred = (0, defer_1.defer)();
waitingClients.push({
deferred,
});
const queuedAt = process.hrtime.bigint();
logger.warn({
waitingClients: waitingClients.length,
}, `connection pool full; client has been queued`);
return waitingClient.promise;
// eslint-disable-next-line promise/prefer-await-to-then
return deferred.promise.then((connection) => {
logger.debug({
connectionId: connection.id(),
duration: Number(process.hrtime.bigint() - queuedAt) / 1e6,
}, 'connection has been acquired from the queue');
return connection;
});
}

@@ -101,0 +111,0 @@ };

@@ -1340,2 +1340,22 @@ "use strict";

});
test('connections are parallelized', async (t) => {
const resetConnection = sinon.spy();
const pool = await (0, __1.createPool)(t.context.dsn, {
driverFactory,
maximumPoolSize: 2,
resetConnection,
});
const [a, b] = await Promise.all([
pool.connect(async (connection) => {
await connection.query(__1.sql.unsafe `SELECT pg_sleep(0.2)`);
return Date.now();
}),
pool.connect(async (connection) => {
await connection.query(__1.sql.unsafe `SELECT pg_sleep(0.1)`);
return Date.now();
}),
]);
t.true(a > b);
await pool.end();
});
test('does not re-use transaction connection if there was an error', async (t) => {

@@ -1342,0 +1362,0 @@ const pool = await (0, __1.createPool)(t.context.dsn, {

@@ -8,4 +8,4 @@ {

"dependencies": {
"@slonik/errors": "^43.0.4",
"@slonik/sql-tag": "^43.0.4",
"@slonik/errors": "^43.0.5",
"@slonik/sql-tag": "^43.0.5",
"@types/pg": "^8.11.6",

@@ -90,3 +90,3 @@ "get-stack-trace": "^3.1.1",

"types": "./dist/index.d.ts",
"version": "43.0.4"
"version": "43.0.5"
}

@@ -35,2 +35,6 @@ import { Logger } from '../Logger';

type WaitingClient = {
deferred: DeferredPromise<ConnectionPoolClient>;
};
type ConnectionPoolStateName = 'ACTIVE' | 'ENDING' | 'ENDED';

@@ -71,3 +75,3 @@

const waitingClients: Array<DeferredPromise<ConnectionPoolClient>> = [];
const waitingClients: WaitingClient[] = [];

@@ -95,3 +99,3 @@ const id = createUid();

await Promise.all(
waitingClients.map((waitingClient) => waitingClient.promise),
waitingClients.map((waitingClient) => waitingClient.deferred.promise),
);

@@ -153,3 +157,3 @@ } catch (error) {

waitingClient.resolve(connection);
waitingClient.deferred.resolve(connection);
};

@@ -172,3 +176,6 @@

// eslint-disable-next-line promise/prefer-await-to-then
acquire().then(waitingClient.resolve, waitingClient.reject);
acquire().then(
waitingClient.deferred.resolve,
waitingClient.deferred.reject,
);
};

@@ -189,6 +196,10 @@

} else {
const waitingClient = defer<ConnectionPoolClient>();
const deferred = defer<ConnectionPoolClient>();
waitingClients.push(waitingClient);
waitingClients.push({
deferred,
});
const queuedAt = process.hrtime.bigint();
logger.warn(

@@ -201,3 +212,14 @@ {

return waitingClient.promise;
// eslint-disable-next-line promise/prefer-await-to-then
return deferred.promise.then((connection) => {
logger.debug(
{
connectionId: connection.id(),
duration: Number(process.hrtime.bigint() - queuedAt) / 1e6,
},
'connection has been acquired from the queue',
);
return connection;
});
}

@@ -204,0 +226,0 @@ };

@@ -1775,2 +1775,29 @@ /* eslint-disable id-length */

test('connections are parallelized', async (t) => {
const resetConnection = sinon.spy();
const pool = await createPool(t.context.dsn, {
driverFactory,
maximumPoolSize: 2,
resetConnection,
});
const [a, b] = await Promise.all([
pool.connect(async (connection) => {
await connection.query(sql.unsafe`SELECT pg_sleep(0.2)`);
return Date.now();
}),
pool.connect(async (connection) => {
await connection.query(sql.unsafe`SELECT pg_sleep(0.1)`);
return Date.now();
}),
]);
t.true(a > b);
await pool.end();
});
test('does not re-use transaction connection if there was an error', async (t) => {

@@ -1777,0 +1804,0 @@ const pool = await createPool(t.context.dsn, {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc