mercurial/commandserver.py
changeset 30891 b1b36c6499c2
parent 30887 a95fc01aaffe
child 30924 48dea083f66d
--- a/mercurial/commandserver.py	Wed Feb 08 14:37:38 2017 -0800
+++ b/mercurial/commandserver.py	Wed Feb 08 14:45:30 2017 -0800
@@ -477,11 +477,23 @@
             self._cleanup()
 
     def _mainloop(self):
+        exiting = False
         h = self._servicehandler
-        while not h.shouldexit():
+        while True:
+            if not exiting and h.shouldexit():
+                # clients can no longer connect() to the domain socket, so
+                # we stop queuing new requests.
+                # for requests that are queued (connect()-ed, but haven't been
+                # accept()-ed), handle them before exit. otherwise, clients
+                # waiting for recv() will receive ECONNRESET.
+                self._unlinksocket()
+                exiting = True
             try:
                 ready = select.select([self._sock], [], [], h.pollinterval)[0]
                 if not ready:
+                    # only exit if we completed all queued requests
+                    if exiting:
+                        break
                     continue
                 conn, _addr = self._sock.accept()
             except (select.error, socket.error) as inst: