I'm trying to harden a Pyro application for production. I am running into the following issue with the Name Server.
If the Name Server is turned off and rapidly turned back on, there seems to be a 50% chance that it will throw the following error:
socket.error: [Errno 98] Address already in use
This can be tested by running the Name Server in a window (pyro4-ns
), hitting CTRL+C, and running it again. Sometimes I can do this 10 times in a row with no problem, but the next 10 times will raise the socket.error
. I've found that it takes about 30 seconds for the Name Server to release the socket when I encounter this error.
I am using supervisord
to control Pyro. I've found the following configuration ameliorates some of the problems. Notably, the startretries=50
will always take longer than the 30 seconds or so it takes the NameServer to release the socket. This way, if the process was to die for some reason, supervisord
can start it without failing.
[program:pyro-ns]
command=pyro4-ns
priority=1
startretries=50
autostart=true
autorestart=true
However, if during the middle of my client execution the Name Server dies, it would take over 30 seconds to reconnect to the NameServer because of this issue. I am using a Pyro client in a webserver for REST tasks, so this delay is not acceptable.
Thanks to Irman for the answer.
If the PYRO_SOCK_REUSE environment is set to True, this error doesn't happen, as it sets SO_REUSEADDR on the socket.
Either:
export PYRO_SOCK_REUSE=True
pyro4-ns
Or in Supervisor's config:
[program:pyro-ns]
environment = PYRO_SOCK_REUSE="True"
command=pyro4-ns