GoogleCloudPlatform / cloud-sql-nodejs-connector

A JavaScript library for connecting securely to your Cloud SQL instances
Apache License 2.0
66 stars 8 forks source link

fix: allow multiple connections via `.startLocalProxy` socket #366

Closed jackwotherspoon closed 2 months ago

jackwotherspoon commented 2 months ago

The .startLocalProxy method of starting a local Unix socket to connect over used .once which was an oversight. This only allows a single connection via the socket. For a connection pool to leverage several connections at once we should use .on.

Tested using Prisma's connection_limit query argument. Using .once only works with connection_limit=1 while using .on allows for connection_limit=2 etc.

Fixes #349

jackwotherspoon commented 2 months ago

Tested this on a local setup with a variation of https://github.com/janpio/21604/tree/main which prints the Prisma metrics. The metrics showcase that indeed more than 1 connection is being created via the connection pool when used with new approach.

When setting connection_limit=3 we can see 3 connections were opened at once...

{
      key: 'prisma_pool_connections_opened_total',
      labels: {},
      value: 3,
      description: 'The total number of pool connections opened'
}