-
Notifications
You must be signed in to change notification settings - Fork 369
solving the unix socket reuse issue #649
Conversation
- added removal of socket file before "bind" operation. necessary in case of unexpected termination of the program and subsequent restart without errors; - added removal of a socket after it is closed in case of errors when creating a socket; - minor optimizations and fixes. Issue: bind(\"unix:/var/run/unit.sock\") failed (98: Address already in use)
|
Hello @mar0x! |
|
Hello, Before removing file, Unit need to make sure it's a unix domain socket and it is abandoned now. To achieve this, it is possible to use file locks, try to connect to socket or something else. |
|
There's already a function that does all the necessary checks in order to avoid various unix socket collisions: https://hg.nginx.org/unit/rev/0a8840921fd0, but at the moment it's only used for the control socket. |
Correct. But the control socket creation procedure does not check the file is a socket (which is Ok for control socket). Perhaps for other listener sockets we want to avoid regular files removal to create unix socket, removing old sockets is Ok. |
Good morning @mar0x, Totally agree with you. I have taken note of all your comments. I'm going to make the necessary corrections. Thank you for your comments, it helps me provide a better solution to the problem.
Good morning @VBart, The problem of not being able to reopen a unix socket only affects the socket as a listener. What @mar0x mentioned does not apply to the control socket, but user mistake is minimized if it is used. From my point of view, listening sockets require more fine-grained control and maintenance. |
|
Anyway, I suggest to avoid code duplication and add the necessary check (i.e. checking file type after ECONNREFUSED) to the function mentioned above, then reuse it for listening sockets. |
@VBart Healthy thought. I already thought about this, but initially I thought that you were forking the code in these two different files on purpose. The labels in |
|
@echolimazulu That split wasn't made by intention. The whole Unit project was forked out of some other project and as a result there are still many leftovers of old code originally intended for different purpose. |
|
I closed this PR, as in the future I will open a new one, taking into account all the changes. I have carefully studied and implemented all your suggestions, such as:
At the moment, I am testing the modified functionality. The changes will affect the following list of files:
Thanks! |
Previously, @VBart suggested replacing the socket creation function to avoid code duplication. nginx#649 (comment) nginx#649 (comment)
This patch solves the problem of reusing unix sockets.
Changes:
Issue #643:
bind(\"unix:/var/run/unit.sock\") failed (98: Address already in use)Notice:
This PR does not solve the problem of removing unix sockets when receiving program termination signals, such as SIGTERM, SIGQUIT and others. This patch only affects the behavior of unix sockets when starting the program.