comparison 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
comparison
equal deleted inserted replaced
32275:cf415777a22c 32276:c8b9943c07eb
42 42
43 import hashlib 43 import hashlib
44 import inspect 44 import inspect
45 import os 45 import os
46 import re 46 import re
47 import socket
47 import struct 48 import struct
48 import time 49 import time
49 50
50 from .i18n import _ 51 from .i18n import _
51 52
514 # use a unique temp address so we can stat the file and do ownership 515 # use a unique temp address so we can stat the file and do ownership
515 # check later 516 # check later
516 tempaddress = _tempaddress(self._realaddress) 517 tempaddress = _tempaddress(self._realaddress)
517 util.bindunixsocket(sock, tempaddress) 518 util.bindunixsocket(sock, tempaddress)
518 self._socketstat = os.stat(tempaddress) 519 self._socketstat = os.stat(tempaddress)
520 sock.listen(socket.SOMAXCONN)
519 # rename will replace the old socket file if exists atomically. the 521 # rename will replace the old socket file if exists atomically. the
520 # old server will detect ownership change and exit. 522 # old server will detect ownership change and exit.
521 util.rename(tempaddress, self._realaddress) 523 util.rename(tempaddress, self._realaddress)
522 524
523 def _createsymlink(self): 525 def _createsymlink(self):