Sometimes query returns empty result set
Hello guys,
I am using node-pg inside node-any-db wrapper with pool min: 100 max: 200 connections. Sometimes result set is empty or incomplete (for example it returns 200 rows instead of 1800). Restarting node application fixes it. While it returns empty result set, I tried to run the query from another node.js cli script using same parameters and it works ok. Any ideas what could it be?
Thank you in advance,
Alex.
and no error messages on logs.
this behavior was noticed for both: native and JS mode.
Can you reproduce the issue without using any-db?
I have not refactor the code yet as it is production application, but going to try to use pg without any-db and will report here.
Have tried node-pg directly (without not-any-db) and the issue was not reported for few weeks, I could not replicate it. Seem like it relates to not-any-db.
Sorry, seems this issue relates to node-pg, it appeared even if I use nodePg.connect(function(){ client.query(); });
What I noticed it was reported only for "heavy" modules, where 3 parallel queries are done more then 300 times. As usual restarting node.js sorts temporary (for few days) Can it be related to memory managing anyhow?
Can you submit code to reproduce this issue?
So far, no. It is part of quite complex program. And just after node.js start it is working alright. I will try to provide additional data if possible.
2013/8/20 Brian C [email protected]
Can you submit code to reproduce this issue?
— Reply to this email directly or view it on GitHubhttps://github.com/brianc/node-postgres/issues/401#issuecomment-22907951 .
I have the same issue: Here is a code which start 5 select queries from database. I've got error on different usernames at each start. PS. There are integrated recursion for repeat request with invalid responses and sleep for make delay between requests. (I thought that help me, but not...)
function isUserConfirmed(username, cnt)
{
logger.log('info','IsUserConfirmed check... USERNAME: ', username);
//Async sleep 100ms
sleep(100, function()
{
//New connection for each request!!!
pg.connect(simplexPgConnectionString, function(err, client, done)
{
if(err) {
logger.log('error', 'Fetching client from pool [%j]', err, {});
}
client.query('SELECT username, confirmed from users where username = $1', [username],
function(err, result)
{
//call done() to release the client back to the pool
done();
logger.log('info','SELECT response [%j]',result, {});
logger.log('info','SELECT rows [%j]',result.rows, {});
if(err)
{
return logger.log('error', 'Error running query [%j]', err, {});
}
var confirmed = false;
if (result.rows[0] != undefined)
{
logger.log('info', "Confirmed: ", result.rows[0].confirmed);
}
else
{
logger.log('warn', 'Undefined!!!');
cnt++;
if (cnt<0) // Recursion steps. 0 - disable recursion.
{
logger.log('warn', 'Hello recursion!!! ['+cnt+']');
isUserConfirmed(username, cnt);
}
}
});
});
});
}
function sleep(time, callback) { var stop = new Date().getTime(); while(new Date().getTime() < stop + time) { ; } callback(); }
var test_message = function() { var errarr = [ "[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]" ]; for (var i = 0; i < 5; i++) { isUserConfirmed(errarr[i], 0); }; } test_message();
P.P.S: This is bad response: (it might be help) SELECT response [{"command":"SELECT","rowCount":0,"oid":null,"rows":[],"fields":[{"name":"username","tableID":1177594,"columnID":2,"dataTypeID":1043,"dataTypeSize":-1,"dataTypeModifier":-1,"format":"text"},{"name":"confirmed","tableID":1177594,"columnID":12,"dataTypeID":16,"dataTypeSize":1,"dataTypeModifier":-1,"format":"text"}],"_parsers":[null,null],"rowAsArray":false}]
Can you take a little time to properly format the code so I can read it?
Did you ever get this figured out? Feel free to reopen if its still causing you problems. Otherwise I'm going to assume you found a fix.
I have the same problem (node version 8.11.1, mssql 2016, mssql/tedious driver) Sample output from a process that fetches data with same conditions repeatedly for 500 times as kind of a load test
Rows returned : 13 Rows returned : 13 Rows returned : 13 Rows returned : 13 Rows returned : 0 Rows returned : 13 Rows returned : 0 Rows returned : 13 Rows returned : 13 Rows returned : 13
@orshee This is the repository for https://www.npmjs.com/package/pg, a PostgreSQL driver.
I have the same problem and it occures very often. Sometimes every 3 to 4 querries. Running ^7.14.0 for NodeJS. I make a count querrie and then a querrie for the data and it occures quiet often that either the count querry or the data querry return empty results.
Edit: It mostly only occures on a system with low performance.
@Darcody I need the version of node, pg, and a self-contained code example that reproduces the problem if you want me to take a look. If you're saying you're using version 7.14 of node.js then that's an unsupported version of node, btw.
Never mind. It was our fault. We have two databases and a consule to which we connect and for some reason the databases were asynchron which resulted to empty results. Sorry for your inconvenience.