Created
November 14, 2017 20:48
-
-
Save rkaw92/9cbd71fdb98d74f01c624bb2a003cd2a to your computer and use it in GitHub Desktop.
Stuck Promises from node-postgres/Client#query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
.