mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
lock domain socket and remove on last arbiter exit
This commit is contained in:
parent
3ccdafbb62
commit
4fc3fbec33
@ -4,6 +4,7 @@
|
||||
# See the NOTICE for more information.
|
||||
|
||||
import errno
|
||||
import fcntl
|
||||
import os
|
||||
import socket
|
||||
import stat
|
||||
@ -105,6 +106,8 @@ class UnixSocket(BaseSocket):
|
||||
raise ValueError("%r is not a socket" % addr)
|
||||
self.parent = os.getpid()
|
||||
super(UnixSocket, self).__init__(addr, conf, log, fd=fd)
|
||||
# each arbiter grabs a shared lock on the unix socket.
|
||||
fcntl.lockf(self.sock, fcntl.LOCK_SH | fcntl.LOCK_NB)
|
||||
|
||||
def __str__(self):
|
||||
return "unix:%s" % self.cfg_addr
|
||||
@ -117,9 +120,17 @@ class UnixSocket(BaseSocket):
|
||||
|
||||
|
||||
def close(self):
|
||||
super(UnixSocket, self).close()
|
||||
if self.parent == os.getpid():
|
||||
os.unlink(self.cfg_addr)
|
||||
# attempt to acquire an exclusive lock on the unix socket.
|
||||
# if we're the only arbiter running, the lock will succeed, and
|
||||
# we can safely rm the socket.
|
||||
try:
|
||||
fcntl.lockf(self.sock, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
os.unlink(self.cfg_addr)
|
||||
super(UnixSocket, self).close()
|
||||
|
||||
|
||||
def _sock_type(addr):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user