bjoern
bjoern copied to clipboard
UNIX communication sockets left in filesystem after receiving a signal
I'm running Bjoern embedded in Python in this way:
logger.info('Bjoern bound to UNIX socket %s', sock_name)
try:
os.unlink(sock_name)
except OSError:
logger.error('Could not remove previous UNIX socket %s', sock_name)
pass
bjoern.run(api_app, 'unix:{}'.format(sock_name))
try:
os.unlink(sock_name)
except OSError:
pass
By default, supervisord sends SIGTERM to processes to quit them, as stated in this issue. Sending this signal, if I wouldn't remove the pending sockets, they prevent bjoern from starting next time, because the old socket is assumed to be in use. I saw there is code for unlinking sockets in bjoern, but it is appearantly bypassed when receiving SIGTERM. Is there any way to make shutdown of bjoern more safe?
OS: Debian 8, Python 2.7.9
Agreed, we probably should use the atexit module instead catching CTRL C. Patch welcome.
I am having trouble replicating the issue, but I have implemented an atexit handler for tearing down the server socket in #155. Could someone verify that this fixes the issue?
I think that your fix will not be working. I've tried to make a simple wrapper that just unlinks the socket with the help of atexit, and it wasn't called. I think that the reason is mentioned there:
Note: The functions registered via this module are not called when the program is killed by a signal not handled by Python, when a Python fatal internal error is detected, or when
os._exit()
is called.
So, the signal seems to be a better option (see #91). Bud even with the signals, it seems that there should be a manual unlink before the run.