Skip to content

Instantly share code, notes, and snippets.

@rkaw92
Created November 14, 2017 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkaw92/9cbd71fdb98d74f01c624bb2a003cd2a to your computer and use it in GitHub Desktop.
Save rkaw92/9cbd71fdb98d74f01c624bb2a003cd2a to your computer and use it in GitHub Desktop.
Stuck Promises from node-postgres/Client#query
* firing query
* query result: 1
* firing query
* query result: 1
* firing query
* query result: 1
* firing query
* query result: 1
* firing query
* query result: 1
<At this point, we shut down PostgreSQL>
* connection error: Error: Connection terminated unexpectedly
* connection end
* firing query
* query error: This socket has been ended by the other party
* firing query
<Note: the second "failing" query is never run because the first still has not left the queue>
* firing query
* firing query
* firing query
* firing query
* firing query
* firing query
* firing query
* firing query
* firing query
* firing query
* firing query
* firing query
* firing query
* firing query
'use strict';
const pg = require('pg');
const client = new pg.Client({ connectionString: 'postgresql://postgres:swordfish@127.0.0.1/postgres' });
client.connect().then(function() {
setInterval(function() {
console.log('* firing query');
client.query('SELECT 1 AS one').then(function(result) {
console.log('* query result: %s', result.rows[0].one);
}, function(error) {
console.log('* query error: %s', error.message);
});
}, 5000);
client.on('end', function() {
console.log('* connection end');
});
client.on('error', function(error) {
console.log('* connection error: %s', error);
});
});
@rkaw92
Copy link
Author

rkaw92 commented Nov 14, 2017

Correction: in the annotated output, line 17 says the previous query has not left the queue. It actually has, but the processing of the queue is still not unlocked because readyForQuery === false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment