-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Uncaught, unspecified 'error' event. #41
Comments
I am not sure where the exception is coming from or what query is causing it, but it is being emitted from node-postgres. Node-postgres process.on('uncaughtException', function(err) {
//do something with the global error here...
//for starters, log it out & send me the output in this github issue ;)
}) |
yep I've actually got that setup to email me when that event is triggered, which is what I pasted above. I put some more debugging in to see if I can get more information about the query when it happens again. Could it be the case that I may be trying to use more connections in my pool? I bumped that up. |
Ah sorry I misunderstood what you were originally saying about the connection. If you use more connections than Postgres allows you'll get a much clearer message from the postgres server saying connection denied like this: { length: 78,
name: 'error',
severity: 'FATAL',
code: '53300',
message: 'sorry, too many clients already',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
file: 'proc.c',
line: '275',
routine: 'InitProcess' } Are you using the callback method of performing queries or the event emitter method? i.e. this: client.query('whatever', function(err, result) { /* handle result */}); or this: var query = client.query('whatever');
query.on('error', function() { /* handle error */ });
query.on('row', function() { /* handle row */}); |
i am using the callback method. |
I'm guessing one of the open sockets in a client which may even be idling in the pool is receiving an error from the socket. Some sort of network blip or connectivity issue. I don't think it's actually related to node-postgres's behavior exactly. It's going to be hard to figure out what's going on without more information on the error. One thing you might want to do is iterate over every client in the pool and attach an 'error' event listener to it so you can intercept the error at a slightly lower level...something like this during your application boot up process: for(var i = 0; i < pg.defaults.poolSize; i++) {
pg.connect('your connection info', function(client, err) {
client.on('error', function(err) {
console.log(client); //this should dump pretty big json structure out with the state of the client, connection, & socket
console.log(err);
})
client.query("SELECT pg_sleep(2)"); //this will make the client run a single 2 second query so this loop can actually be sure to get a reference to each client in the pool...as they will all be made active by the query
});
} This is a really hacky way to do this and makes me realize I need to look at the client-pool API and make it more user friendly. Anyways...this will allow you to attach an error handler to each |
Looks like it was the too many client error, our postgres server wasn't allowing enough connections... sorry to bug ya, thx for looking into it though. |
One question though. It appears that this module just grabs connections as needed instead of grabbing them all at once. Is that correct? And I'm assuming it releases them all on app shutdown? |
correct, it grabs them as needed. You have to manually shut the pool down at app shutdown by calling |
I'm glad you found a solution. You weren't bugging me in the slightest. |
Not sure if I'm doing something wrong or something erronous is happening. This is a stack trace I get from my app running in production... don't have more than that. It is using the JS driver. Any ideas?
The text was updated successfully, but these errors were encountered: