pgtoolkit/pgmanager.py
changeset 37 5b0eb4b11940
parent 36 e67101c22e83
child 41 6aad5e35efe8
--- a/pgtoolkit/pgmanager.py	Wed May 23 11:11:16 2012 +0200
+++ b/pgtoolkit/pgmanager.py	Wed May 23 16:02:53 2012 +0200
@@ -182,7 +182,7 @@
 
     def keep_alive(self):
         '''Set socket to keepalive mode. Must be called before any query.'''
-        sock = socket.fromfd(self.fileno(), socket.AF_INET, socket.SOCK_STREAM) 
+        sock = socket.fromfd(self.fileno(), socket.AF_INET, socket.SOCK_STREAM)
         sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
         try:
             # Maximum keep-alive probes before asuming the connection is lost
@@ -193,6 +193,8 @@
             sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 10)
         except socket.error:
             pass
+        # close duplicated fd, options set for socket stays
+        sock.close()
 
 
 class PgManager: