Skip to content

No error emitted on ungraceful db server shutdown #1113

Closed

Description

@simopahk

When a database server goes down unnoticed, a single connected client will not emit any errors and continue living up to ~15 minutes until (in a specific case, 'EHOSTUNREACH') socket error is emitted. Setting keepAlive to true in client configuration does not have the desired effect, because the connection object sets _ending to true after sending off the first query (

con.sync();
), which in turn forces 'ECONNRESET' socket events to be ignored (https://github.com/brianc/node-postgres/blob/master/lib/connection.js#L68).

Activity

  1. vitaly-t commented on Aug 18, 2016

    @vitaly-t
    Contributor

    I know this may not be of immediate help to yourself, but in general, this will help everybody...

    Please try to replicate your test with pg-promise. If it doesn't happen, then we will know for sure that the issue is related to post - v.5.1.0 changes, related to the new connection pool, and if it does happen, well, then it is something else entirely.

    I did a lot in that library to make sure the server disconnection is handled properly and gracefully, up till version 5.1.0 of the node-postgres driver.

    Also see event error there that should get called when a disconnection happens, as per the API (see the example there).

  2. simopahk commented on Aug 18, 2016

    @simopahk
    Author

    I gave your library a try. When I took the database down during an uncommited transaction, I received the error 'Abnormal client.end() call, due to invalid code or failed server connection.' - thus, ungraceful disconnection handling seems to work well in pg-promise.

  3. vitaly-t commented on Aug 18, 2016

    @vitaly-t
    Contributor

    @riimeik thank you!

    Now we know for sure the issue was introduced somehow with the new connection pool, after version 5.1.0

    As for this error message: Abnormal client.end() call, due to invalid code or failed server connection., pg-promise throws it when the integrated pool is trying to release a dead connection, via a direct call client.end(), so the library simply reports it that way.

  4. vitaly-t commented on Aug 19, 2016

    @vitaly-t
    Contributor

    @brianc I have seen this issue more than once myself, when trying to upgrade pg-promise to use version 6.x of node-postgres.

    At some point I had a fairly usable reproduction test, which then stopped working and I couldn't come up with reliable reproduction scenario ever since.

    This should not stop us from trying. We need steps for reproducing the problem, for it is definitely there. And while it is there, I cannot upgrade pg-promise to 6.x of node-postgres. Restoring the database connection reliably is a very serious issue.

  5. brianc commented on Aug 19, 2016

    @brianc
    Owner

    If you get it figured out I'd love a pull request with the fix! ❤️

  6. vitaly-t commented on Aug 19, 2016

    @vitaly-t
    Contributor

    @riimeik is there any chance you would take it one step further and create a reliable reproduction test for us? This would be much appreciated!

    I myself have tried it twice, without success. I can only see it sometimes, unfortunately, not enough to suggest any fix.

  7. brianc commented on Aug 26, 2016

    @brianc
    Owner

    @riimeik - if you can't come up with code to reproduce the issue, will you let me know the exact steps you took to reproduce the issue locally? Maybe I can come up with a way to do the same thing in a test & reproduce what's going on. I'd like to get this fixed.

  8. added this to the pg@7.0 milestone on May 24, 2017
  9. brianc commented on Jun 12, 2017

    @brianc
    Owner

    @riimeik - I've fixed this issue in the most recent release of node-postgres. Sorry for the delay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions