-
Notifications
You must be signed in to change notification settings - Fork 66
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
How to ensure single daemon process? #2
Comments
I think there is a race condition where two daemons could be started at the same time, read the config file notice that the pid field is notbset and then write to the same repo. Also if the daemon crashes it will leave the pid field set in he config. The daemon could create a unix socket in the |
@bjorn3 I like this approach. It's clean. Why not use TCP sockets? that way it would work on Windows too. Does it require any elevated permissions to listen to a socket on localhost? On any OS that you're aware of |
A TCP socket only works when there is a single user on the local machine. It requires picking a port that isn't used by any other service. It may get blocked by a firewall (On windows you get a popup the first time it runs AFAIK. I'm not sure if you need admin permission to allow it.) And it may show up in port scans done by websites yoy visit like for example ebay is known to do. TCP sockets may be a fine alternative when unix domain sockets are unavailable, but I think unix domain sockets are better for things like this. OS portability is not a big deal. Even windows 10 now supports them (not sure if libstd already exposes them on windows. if not you can use winapi) |
@bjorn3 Another example where this is important is tests. Right now I have a Regarding sockets — my bias is toward going full-fledged HTTP, because you always seem to want more out of stuff like this. Like:
I suppose compatibility with other tools (e.g. |
If you use http please make sure to check that the |
Right now there are some safeguards to ensure that only a single daemon process is running.
Consequences of multiple daemons:
Right now, we read the runtime database file at the beginning of each loop iteration. If the
pid
does not equal the current process' ID, then the process kills itself.Please comment if you think this algorithm is inadequate.
The text was updated successfully, but these errors were encountered: