# HG changeset patch # User Jun Wu # Date 1493575707 25200 # Node ID c8b9943c07ebeba32ec96a5f30362bdc3e572f4d # Parent cf415777a22c895b72aac0429a1acdebeda68b4b 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. diff -r cf415777a22c -r c8b9943c07eb mercurial/chgserver.py --- 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) diff -r cf415777a22c -r c8b9943c07eb mercurial/commandserver.py --- a/mercurial/commandserver.py Mon May 08 15:31:34 2017 -0700 +++ b/mercurial/commandserver.py Sun Apr 30 11:08:27 2017 -0700 @@ -409,6 +409,7 @@ def bindsocket(self, sock, address): util.bindunixsocket(sock, address) + sock.listen(socket.SOMAXCONN) def unlinksocket(self, address): os.unlink(address) @@ -452,7 +453,6 @@ def init(self): self._sock = socket.socket(socket.AF_UNIX) self._servicehandler.bindsocket(self._sock, self.address) - self._sock.listen(socket.SOMAXCONN) o = signal.signal(signal.SIGCHLD, self._sigchldhandler) self._oldsigchldhandler = o self._servicehandler.printbanner(self.address)