diff mercurial/chgserver.py @ 32276:c8b9943c07eb

commandserver: move "listen" responsibility from service to handler This enables chg to replace a server socket in an atomic way: 1. bind to a temp address 2. listen 3. rename Currently 3 happens before 2 so a client may see the socket file but fails to connect to it.
author Jun Wu <quark@fb.com>
date Sun, 30 Apr 2017 11:08:27 -0700
parents d74b0cff94a9
children 1ada3d18e7fb
line wrap: on
line diff
--- a/mercurial/chgserver.py	Mon May 08 15:31:34 2017 -0700
+++ b/mercurial/chgserver.py	Sun Apr 30 11:08:27 2017 -0700
@@ -44,6 +44,7 @@
 import inspect
 import os
 import re
+import socket
 import struct
 import time
 
@@ -516,6 +517,7 @@
         tempaddress = _tempaddress(self._realaddress)
         util.bindunixsocket(sock, tempaddress)
         self._socketstat = os.stat(tempaddress)
+        sock.listen(socket.SOMAXCONN)
         # rename will replace the old socket file if exists atomically. the
         # old server will detect ownership change and exit.
         util.rename(tempaddress, self._realaddress)