-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
We're experiencing database server performance issues caused by sessions spending the vast majority of time in the ClientRead
state. A few other similar issues have been opened: #1774, #1993, #1952.
To reproduce:
var pg = require("pg"); // or require("pg").native
var client = new pg.Client({
connectionString: "postgres://postgres@localhost/postgres"
});
client.connect();
client.query("SELECT 1", function(_error, _rows) {
while (true) {}
});
Run the above, it will hang in the while
loop. In another terminal run:
$ psql --username postgres --command "SELECT * FROM pg_stat_activity WHERE wait_event = 'ClientRead' AND query = 'SELECT 1'"
We can see the query stuck in ClientRead
.
The problem here is that node-postgres is executing the response callback before the session is out of the ClientRead
state. This is isn't optimal: any CPU time spent in the callback prevents the PostgreSQL server from executing the query.
Would it be possible for node-postgres to execute the callback only after the server is able to execute the query?
Thanks in advance! We get a tremendous amount of value from node-postgres.