Leandro Lucarella escribió:
>> I could try to build some form of keepalive support, but I don't have much
>> time to work on it at the moment.  There does seem to be some keepalive
>> mechanism in libpq; I guess that using it would also require help from the
>> application.
> 
> One thing I don't understand. libpqxx tries to reestablish the 
> connection because of the bug, and if that bug is fixed the keep-alive 
> would not be necessary?

Hi, I was trying to solve this problem, do I did this ("pseudocode"):

pqxx::connection c(conn_str);
// Use TCP keep-alive feature
setsockopt(c.sock(), SOL_SOCKET, SO_KEEPALIVE, 1);
// Maximum keep-alive probes before asuming the connection is lost
setsockopt(c.sock(), IPPROTO_TCP, TCP_KEEPCNT, 5);
// Interval (in seconds) between keep-alive probes
set_sock_opt(c->sock(), IPPROTO_TCP, TCP_KEEPINTVL, 2);
// Maximum idle time (in seconds) before start sending keep-alive probes
set_sock_opt(c->sock(), IPPROTO_TCP, TCP_KEEPIDLE, 10);

I then see what happens when I disconnect the network cable and looking 
at netstat -pano, I see how the keep alive probes are sent and how the 
OS closes the connection as the keep-alive probes fails. But I don't get 
the pqxx::broken_connection exception either. I see the connection is 
re-opened, but without the keep-alive tunning I've done, so the time out 
of the new socket is horribly long for what I need.

Is there any automatic reconnection code in pqxx or libpq? If so, is 
there any way to avoid it? If not, is there any way to tell then to 
excecute some arbitrary code on the socket any time is opened (to tune 
my keep-alive parameters)?

Thanks!

-- 
Leandro Lucarella
Integratech S.A.
4571-5252
_______________________________________________
Libpqxx-general mailing list
[email protected]
http://gborg.postgresql.org/mailman/listinfo/libpqxx-general

Reply via email to