node-pg-native icon indicating copy to clipboard operation
node-pg-native copied to clipboard

pg-native blocks node http server

Open jacott opened this issue 10 years ago • 7 comments

This might be related to the promises bug #16

In my prod code it blocks for 20 seconds but as a gist it blocks indefinately

var pg = require('pg-native');
var http = require('http');
var server = http.createServer(function () {});

var c = new pg();
c.connect("host=/var/run/postgresql", function (a1, a2) {

  // comment out the query line below and listen does not block
  c.query('SELECT 1 AS a', function () {
    var st = Date.now();
    console.log('listen');

    server.listen(3123, '0.0.0.0', function () {
      console.log('finished', Date.now() - st);

      server.close();
      c.end(function () {
        console.log('done');
      });
    });
  });
});


jacott avatar Jun 02 '15 01:06 jacott

The reason in my prod code that it blocks for 20 seconds is because generic-pool destroys the connection after 20s

jacott avatar Jun 05 '15 18:06 jacott

Yeah this is a problem - I'll definitely see about getting a fix for this some time over the weekend. I'm pretty busy and don't have much time to devote to open source right now, but blocking the event loop is pretty bogus.

On Fri, Jun 5, 2015 at 2:27 PM, Geoff Jacobsen [email protected] wrote:

The reason in my prod code that it blocks for 20 seconds is because generic-pool destroys the connection after 20s

— Reply to this email directly or view it on GitHub https://github.com/brianc/node-pg-native/issues/21#issuecomment-109388456 .

brianc avatar Jun 08 '15 15:06 brianc

By the way...if you're able to reproduce this easily and repeatably in a small self contained piece of code that would help me write some tests for this when I get started.

On Mon, Jun 8, 2015 at 11:59 AM, Brian Carlson [email protected] wrote:

Yeah this is a problem - I'll definitely see about getting a fix for this some time over the weekend. I'm pretty busy and don't have much time to devote to open source right now, but blocking the event loop is pretty bogus.

On Fri, Jun 5, 2015 at 2:27 PM, Geoff Jacobsen [email protected] wrote:

The reason in my prod code that it blocks for 20 seconds is because generic-pool destroys the connection after 20s

— Reply to this email directly or view it on GitHub https://github.com/brianc/node-pg-native/issues/21#issuecomment-109388456 .

brianc avatar Jun 08 '15 16:06 brianc

That is what code example above does.

jacott avatar Jun 08 '15 22:06 jacott

BTW I have written my own replacement for node-libpq which just does all the blocking stuff in worker threads. node-pg-libpq

jacott avatar Jun 08 '15 22:06 jacott

@jacott nice job for releasing node-pg-libpq, seems to be clever solution to just map libpq calls to javascript. I came to this issue because I have got another issue, the result set is coming empty and who knows why. And I am kind of thinking where to invest my time: look for bugs in Brian's code or replace everything with your stuff.

nuliknol avatar Jan 29 '17 03:01 nuliknol

@nuliknol I suggest trying using both for a trial period; see if node-pg-libpq solves your problem. I use and support it for my day job but I'm not aware of many other people using it

jacott avatar Jan 30 '17 08:01 jacott