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
When running concurrent queries inside cron jobs, queries get stuck indefinitely if one of the running queries is a static query (i.e., not parameterized).
I set the max connection to 1 to reproduce the issue quickly, but even with the default max = 10, the queries still eventually get stuck.
All the connections appear to be stuck in the full queue, which causes new queries to pile up in the queries queue.
Environment
node version: v22.12.0
database: Supabase with transaction pooling (port: 6543)
postgres.js version: v3.4.5
Steps to Reproduce
Code to Reproduce the Issue:
constexpress=require("express");const{ CronJob }=require("cron");constpostgres=require("postgres");require("dotenv").config();constapp=express();constPORT=3000;constsql=postgres({host: process.env.DATABASE_HOST,port: process.env.DATABASE_PORT,database: "postgres",username: process.env.DATABASE_USERNAME,password: process.env.DATABASE_PASSWORD,prepare: false,max: 1,});newCronJob("*/1 * * * * *",async()=>{try{console.log("[Cron 1] Update User");// static query (causes stuck query)constdata=awaitsql` UPDATE users SET name = 'Henry' WHERE id = 'f35e9116-eeda-47d9-9b5e-8444a057a919' RETURNING * `;console.log(`[Cron 1] Updated User Data: ${data.length}`);}catch(error){console.error(error);}},null,true,null,null,false,null,false,true);newCronJob("*/1 * * * * *",async()=>{try{console.log("[Cron 2] Update User");// parameterized queryconstdata=awaitsql` UPDATE users SET name = 'Henry' WHERE id = ${"f35e9116-eeda-47d9-9b5e-8444a057a919"} RETURNING * `;console.log(`[Cron 2] Updated User Data: ${data.length}`);}catch(error){console.error(error);}},null,true,null,null,false,null,false,true);app.listen(PORT,()=>{console.log(`Server is running on http://localhost:${PORT}`);});
Running the above code causes the queries to hang, producing output similar to the example below. The query appears to be stuck in ClientRead. However, once you parameterize the first query's WHERE id = 'f35e9116-eeda-47d9-9b5e-8444a057a919' by changing it to WHERE id = ${"f35e9116-eeda-47d9-9b5e-8444a057a919"}, it runs fine.
Server is running on http://localhost:3000
[Cron 1] Update User
[Cron 2] Update User
[Cron 1] Updated User Data: 1
[Cron 2] Updated User Data: 1
[Cron 1] Update User
[Cron 2] Update User
[Cron 1] Updated User Data: 1
[Cron 2] Updated User Data: 1
[Cron 1] Update User
[Cron 2] Update User
[Cron 1] Updated User Data: 1
[Cron 1] Update User
The text was updated successfully, but these errors were encountered:
When running concurrent queries inside cron jobs, queries get stuck indefinitely if one of the running queries is a static query (i.e., not parameterized).
I set the
max
connection to 1 to reproduce the issue quickly, but even with the defaultmax = 10
, the queries still eventually get stuck.All the connections appear to be stuck in the
full
queue, which causes new queries to pile up in thequeries
queue.Environment
6543
)Steps to Reproduce
Code to Reproduce the Issue:
Running the above code causes the queries to hang, producing output similar to the example below. The query appears to be stuck in
ClientRead
. However, once you parameterize the first query'sWHERE id = 'f35e9116-eeda-47d9-9b5e-8444a057a919'
by changing it toWHERE id = ${"f35e9116-eeda-47d9-9b5e-8444a057a919"}
, it runs fine.The text was updated successfully, but these errors were encountered: