bjoern icon indicating copy to clipboard operation
bjoern copied to clipboard

UNIX communication sockets left in filesystem after receiving a signal

Open rkrell opened this issue 6 years ago • 3 comments

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

rkrell avatar Nov 08 '18 22:11 rkrell

Agreed, we probably should use the atexit module instead catching CTRL C. Patch welcome.

jonashaag avatar Nov 09 '18 10:11 jonashaag

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?

samipfjo avatar Mar 16 '19 19:03 samipfjo

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.

m190 avatar Jul 21 '19 11:07 m190