You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import { onRequest } from 'firebase-functions/v2/https';
import { getBdConfig } from '../../submodules/for-backend/postgres';
import { Pool } from 'pg';
const pool: Pool | undefined;
export const exampleCloudFunction = onRequest(
async (
//...
) => {
// initialize global pool if not initialized
if (!pool) {
pool = new Pool(getBdConfig(postgresSecrets));
}
const client = await pool!.connect();
try {
//...
// Run business logic and queries
} finally {
client.release();
}
}
Problem
After some successful requests I'm getting connection timeout when running pool!.connect();, even when I add to retry 3 times. Any idea of what might be causing it?
For example in one case, it ran for 6 requests successfully than it failed on the 7th and kept working for the others 3 request. It took 2 min from the first request to the failed one. Another example, it ran successfully for 194 requests and failed on 3 requests.
I added some logs and there is only 1 connection, 0 idle and 0 waiting in the pool after the connection timeout.
Similar problems:
I read these other issues, but I'm still not sure what it is. Some about Lambda closing TCP connections after some time.
@gajus I figure out what was happening on my side. It was a problem with the VPC connector from GCP and not related to node-postgres. As soon as I removed the VPC connector, the connection timeout was reduced from 1 every 6 attempts to 1 in every 600 attempts. Then a simple retry worked fine.
I will close this issue. I hope this helps you and future developers.
Context
Pool
for reutilizing it between function requests, but I create aPoolClient
for each requestCode example
The code would look something like this:
Problem
After some successful requests I'm getting connection timeout when running
pool!.connect();
, even when I add to retry 3 times. Any idea of what might be causing it?For example in one case, it ran for 6 requests successfully than it failed on the 7th and kept working for the others 3 request. It took 2 min from the first request to the failed one. Another example, it ran successfully for 194 requests and failed on 3 requests.
I added some logs and there is only 1 connection, 0 idle and 0 waiting in the pool after the connection timeout.
Similar problems:
I read these other issues, but I'm still not sure what it is. Some about Lambda closing TCP connections after some time.
The text was updated successfully, but these errors were encountered: