[PATCH] Close keepalive connections to fix pserver traceback

Andrei Vermel avermel at mail.ru
Mon Feb 19 03:43:28 CST 2007


Attached patch is to fix server displaying following after any access except 
clone:

Exception happened during processing of request from ('127.0.0.1', 2915)
Traceback (most recent call last):
  File "C:\Python24\lib\SocketServer.py", line 463, in 
process_request_thread
    self.finish_request(request, client_address)
  File "C:\Python24\lib\SocketServer.py", line 254, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "c:\python24\Lib\site-packages\mercurial\hgweb\server.py", line 42, 
in __
init__
    BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, *args, **kargs)
  File "C:\Python24\lib\SocketServer.py", line 521, in __init__
    self.handle()
  File "C:\Python24\lib\BaseHTTPServer.py", line 318, in handle
    self.handle_one_request()
  File "C:\Python24\lib\BaseHTTPServer.py", line 299, in handle_one_request
    self.raw_requestline = self.rfile.readline()
  File "C:\Python24\lib\socket.py", line 340, in readline
    data = self._sock.recv(self._rbufsize)
error: (10054, 'Connection reset by peer')

# HG changeset patch
# User "Andrei Vermel <avermel at mail.ru>"
# Date 1171877938 -10800
# Node ID c82de89ec4a4391d4368d058f9f4c9c29a7424d2
# Parent  0e9ab34a181597f8f3b81bf699d5dc5c53f99291
Close keepalive connections to fix pserver traceback

diff -r 0e9ab34a1815 -r c82de89ec4a4 mercurial/httprepo.py
--- a/mercurial/httprepo.py  Thu Feb 15 12:51:48 2007 +0300
+++ b/mercurial/httprepo.py  Mon Feb 19 12:38:58 2007 +0300
@@ -140,7 +140,7 @@ class httprepository(remoterepository):

         proxyurl = ui.config("http_proxy", "host") or 
os.getenv('http_proxy')
         # XXX proxyauthinfo = None
-        handlers = [httphandler()]
+        self.handlers = [httphandler()]

         if proxyurl:
             # proxy can be proper url or host[:port]
@@ -172,7 +172,7 @@ class httprepository(remoterepository):
                     proxyscheme, netlocunsplit(proxyhost, proxyport,
                                                proxyuser, proxypasswd or 
''),
                     proxypath, proxyquery, proxyfrag))
-                handlers.append(urllib2.ProxyHandler({scheme: proxyurl}))
+                self.handlers.append(urllib2.ProxyHandler({scheme: 
proxyurl}))
                 ui.debug(_('proxying through http://%s:%s\n') %
                           (proxyhost, proxyport))

@@ -191,13 +191,18 @@ class httprepository(remoterepository):
                      (user, passwd and '*' * len(passwd) or 'not set'))
             passmgr.add_password(None, host, user, passwd or '')

-        handlers.extend((urllib2.HTTPBasicAuthHandler(passmgr),
+        self.handlers.extend((urllib2.HTTPBasicAuthHandler(passmgr),
                          urllib2.HTTPDigestAuthHandler(passmgr)))
-        opener = urllib2.build_opener(*handlers)
+        opener = urllib2.build_opener(*self.handlers)

         # 1.0 here is the _protocol_ version
         opener.addheaders = [('User-agent', 'mercurial/proto-1.0')]
         urllib2.install_opener(opener)
+
+    def __del__(self):
+        for h in self.handlers:
+            if(hasattr(h, "close_all")):
+                h.close_all()

     def url(self):
         return self.path
-------------- next part --------------
A non-text attachment was scrubbed...
Name: close_connections
Type: application/octet-stream
Size: 2143 bytes
Desc: not available
Url : http://www.selenic.com/pipermail/mercurial-devel/attachments/20070219/cca6ad8a/close_connections.obj


More information about the Mercurial-devel mailing list