Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

early timeout on LISTEN query #74

Closed
Lheurt opened this issue Nov 25, 2011 · 2 comments
Closed

early timeout on LISTEN query #74

Lheurt opened this issue Nov 25, 2011 · 2 comments

Comments

@Lheurt
Copy link

Lheurt commented Nov 25, 2011

I properly receive "notification" events when I issue a LISTEN query, but the connection seems to timeout rather fast (about 15 seconds in). I can't seem to find anyway to prevent the timeout or catch it when it happens. Any existing solution to this ?

pg.connect(pgConnectionString, function(err, client) {
    client.query('LISTEN "watcher"');
    client.on('notification', function(data) {
        console.log(data.payload);
    });
});
@brianc
Copy link
Owner

brianc commented Nov 26, 2011

pg.connect is use to create pooled connections. Using a connection pool connection for listen events really isn't supported or a good idea though I can see how this could be a very easy mistake to make.

To 'listen' a connection by definition must stay open permanently. For a connection to stay open permanently it can never be returned to the connection pool.

Try creating a stand-alone client when you need to handle listen events:

var client = new Client(pgConnectionString);
client.connect();
client.query('LISTEN "watcher"');
client.on('notification', function(data) {
});

<3

@Lheurt
Copy link
Author

Lheurt commented Nov 26, 2011

Thanks a lot for the clarification. I've updated my script with your example and everything's fine now.

@Lheurt Lheurt closed this as completed Nov 26, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants