Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UNIX communication sockets left in filesystem after receiving a signal #146

Open
rkrell opened this issue Nov 8, 2018 · 3 comments
Open

Comments

@rkrell
Copy link

rkrell commented Nov 8, 2018

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

@jonashaag
Copy link
Owner

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

@samipfjo
Copy link

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?

@m190
Copy link

m190 commented Jul 21, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants