DB hangs with postgres and broken network link

29 views
Skip to first unread message

Curtis Dutton

unread,
Jul 3, 2020, 10:51:45 AM7/3/20
to Racket Users List
I'm in the process of writing a simple daemon that periodically checks in with a postgres database. I'm trying to make it resilient with network outages. 


If you connect to the database.
Unplug the network cable.
Run a query.

The query will hang for what appears to be forever without throwing an exception. 

Is this expected behavior?


Thanks,
    Curtis

Curtis Dutton

unread,
Jul 3, 2020, 11:07:17 AM7/3/20
to Racket Users List
Ok well on additional investigation this appears only to happen while using virtual connections. If a raw postgresql-connect is used it does raise a tcp timeout error.

Ryan Culpepper

unread,
Jul 3, 2020, 3:31:31 PM7/3/20
to Curtis Dutton, Racket Users List
Hi Curtis, thanks for the report. No, that isn't supposed to happen. I haven't managed to reproduce a silent hang, and looking over the virtual-connection code it looks like any errors (eg, TCP timeout) should be propagated to the caller. On the other hand, I don't have a way of simulating a network outage for testing, so maybe in that case the connection never realizes it is no longer connected, unlike the things I tried.

Could you run your program with db logging at the debug level (eg, set the environment variable PLTSTDERR to "debug@db error") and also add `#:debug? #t` to your call to `postgresql-connect` and see what gets logged/printed before the hang occurs? (You may want to redact the output.)

Ryan

--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAPChLEqzeN3FjhD59tTHUf3EFgW8Bo0xi_3e3Va5kPg2Ut7miA%40mail.gmail.com.

James Platt

unread,
Jul 3, 2020, 6:18:44 PM7/3/20
to Racket Users List
I wonder if this is a more general TCP/IP issue rather than anything Postgres specific. I'm troubleshooting an issue where a TCP connection to a server is unexpectedly going down, once in a while, with no obvious indication. The solution, for now, is to have the client send a sort of ping over the TCP connection to the server every so often and then establish a new connection if it doesn't get a response. In other words, when the connection goes down, trying to send something over it from the client does not generate an error. I haven't found an indication on either the client or server. So, to detect the connection failure, you have to look for a lack of response. This is an intermittent failure and, as such, very annoying to troubleshoot.
Reply all
Reply to author
Forward
0 new messages