(please Cc me on replies, I am not subscribed)

Hi,

libpq currently does not use TCP keepalives.  This is a problem in our
case where we have some clients waiting for notifies and then the
connection is dropped on the server side.  The client never gets the FIN
and thinks the connection is up.  The attached patch unconditionally
adds keepalives.  I chose unconditionally as this is what the server
does.  We didn't need the ability to tune the timeouts, but that could
be added with reasonable ease.

-- 
Tollef Fog Heen 
UNIX is user friendly, it's just picky about who its friends are
*** a/src/interfaces/libpq/fe-connect.c
--- b/src/interfaces/libpq/fe-connect.c
***************
*** 1321,1326 **** keep_going:						/* We will come back to here until there is
--- 1321,1338 ----
  						continue;
  					}
  #endif   /* F_SETFD */
+ 					optval = 1;
+ 					if (setsockopt(conn->sock, SOL_SOCKET, SO_KEEPALIVE,
+ 						       (char *) &optval, sizeof(optval)) == -1)
+ 					{
+ 						appendPQExpBuffer(&conn->errorMessage,
+ 										  libpq_gettext("could not set keepalive on socket: %s\n"),
+ 							SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
+ 						closesocket(conn->sock);
+ 						conn->sock = -1;
+ 						conn->addr_cur = addr_cur->ai_next;
+ 						continue;
+ 					}
  
  					/*----------
  					 * We have three methods of blocking SIGPIPE during
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to