<div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hello, after discussion, I change the patch below, store the socket when the main process creates it, then delete it in runtime_exit.</div><div><br></div><div># HG changeset patch<br># User stdanley <<a href="mailto:shanlei@asiainfo.com">shanlei@asiainfo.com</a>><br># Date 1651904970 -28800<br># Sat May 07 14:29:30 2022 +0800<br># Node ID c6aa8691ca3c7f92b5645547c8a182f34503a758<br># Parent df887748fffb281302ef02aef1d13037355d749c<br>clean unit socket file before leave<br><br>diff -r df887748fffb -r c6aa8691ca3c src/nxt_main_process.c<br>--- a/src/nxt_main_process.c Wed Dec 15 12:18:59 2021 +0100<br>+++ b/src/nxt_main_process.c Sat May 07 14:29:30 2022 +0800<br>@@ -1070,6 +1070,7 @@<br><br> type = NXT_PORT_MSG_RPC_READY_LAST | NXT_PORT_MSG_CLOSE_FD;<br><br>+ nxt_runtime_listen_socket_add(task->thread->runtime,sa);<br> } else {<br> size = ls.end - ls.start;<br><br>diff -r df887748fffb -r c6aa8691ca3c src/nxt_runtime.c<br>--- a/src/nxt_runtime.c Wed Dec 15 12:18:59 2021 +0100<br>+++ b/src/nxt_runtime.c Sat May 07 14:29:30 2022 +0800<br></div># HG changeset patch<br># User stdanley <<a href="mailto:shanlei@asiainfo.com">shanlei@asiainfo.com</a>><br># Date 1651904970 -28800<br># Sat May 07 14:29:30 2022 +0800<br># Node ID c6aa8691ca3c7f92b5645547c8a182f34503a758<br># Parent df887748fffb281302ef02aef1d13037355d749c<br>clean unit socket file before leave<br><br>diff -r df887748fffb -r c6aa8691ca3c src/nxt_main_process.c<br>--- a/src/nxt_main_process.c Wed Dec 15 12:18:59 2021 +0100<br>+++ b/src/nxt_main_process.c Sat May 07 14:29:30 2022 +0800<br>@@ -1070,6 +1070,7 @@<br><br> type = NXT_PORT_MSG_RPC_READY_LAST | NXT_PORT_MSG_CLOSE_FD;<br><br>+ nxt_runtime_listen_socket_add(task->thread->runtime,sa);<br> } else {<br> size = ls.end - ls.start;<br><br>diff -r df887748fffb -r c6aa8691ca3c src/nxt_runtime.c<br>--- a/src/nxt_runtime.c Wed Dec 15 12:18:59 2021 +0100<br>+++ b/src/nxt_runtime.c Sat May 07 14:29:30 2022 +0800</div><div dir="ltr">+<br>+ curr = rt->listen_sockets->elts;<br>+ ncurr = rt->listen_sockets->nelts;<br>+ for ( c=0;c<ncurr; c++) {<br>+ sa= curr[c].sockaddr;<br>+ if (sa->u.sockaddr.sa_family == AF_UNIX) {<br>+ name = (nxt_file_name_t *) sa->u.sockaddr_un.sun_path;<br>+ (void) nxt_file_delete(name);<br>+ }<br>+ }<br> }<br> #endif<br> }</div><div dir="ltr"><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Apr 29, 2022 at 4:37 PM lei shan <<a href="mailto:shanlei@asiainfo.com">shanlei@asiainfo.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">---------- Forwarded message ---------<br>From: <b class="gmail_sendername" dir="auto">lei shan</b> <span dir="auto"><<a href="mailto:shanlei@asiainfo.com" target="_blank">shanlei@asiainfo.com</a>></span><br>Date: Fri, 29 Apr 2022, 16:36<br>Subject: Re: [PATCH]: unlink legacy unix socket when unit starts<br>To: Александр Поволоцкий <<a href="mailto:tarkhil@over.ru" target="_blank">tarkhil@over.ru</a>><br></div><br><br><div dir="auto">I am working on it, just as control socket did.<div dir="auto">The idea is when the main process create the pipe, it stores the socket in runtime' listening_conntions, then remove it in runtime_exit of the main process.</div><div dir="auto"><br></div><div dir="auto">The cleaning can't be done by router is :</div><div dir="auto">The Unix socket owned by root user</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 29 Apr 2022, 14:09 Александр Поволоцкий, <<a href="mailto:tarkhil@over.ru" rel="noreferrer" target="_blank">tarkhil@over.ru</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<p>No patch will remove pipe on kill -9. We need to implement the
logic used for control socket.<br>
</p>
<div>On 29.04.2022 8:34, lei shan wrote:<br>
</div>
<blockquote type="cite">
<div dir="auto">Hello guys,
<div dir="auto"><br>
</div>
<div dir="auto">The process may crash, or other may misconfig
and cause the file confliction.
<div dir="auto">But at least, unit should remove the pipe
file on exit,as it already does to the control pipe.</div>
<div dir="auto"> </div>
<div dir="auto">So a patch should remove the Unix pipe on stop
, instead of on startup.</div>
<div dir="auto"><br>
</div>
<div dir="auto">Can we agree on this?</div>
<div dir="auto"><br>
</div>
<div dir="auto">Thanks & Best Regards</div>
<div dir="auto"><br>
</div>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Wed, 27 Apr 2022, 05:45
Oleg A. Mamontov, <<a href="mailto:oleg@mamontov.net" rel="noreferrer noreferrer" target="_blank">oleg@mamontov.net</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wed, Apr
27, 2022 at 05:11:26AM +1000, Scott van Kalken wrote:<br>
>This will work well for cases where unit shuts down
gracefully. If unit does<br>
>not shut down gracefully, then i think you will have the
same startup problem. <br>
><br>
>It’s a good point about the TCP socket. <br>
<br>
It seems the key point is the way to check on startup whether
the unix<br>
socket is stale or currently in use and then to decide remove
it and<br>
re-create or just fail the start, isn't it? <br>
<br>
>On Tue, 26 Apr 2022 at 11:50 am, <<a href="mailto:shanlei@asiainfo.com" rel="noreferrer noreferrer noreferrer" target="_blank">shanlei@asiainfo.com</a>>
wrote:<br>
><br>
> I have reconsided the situation:<br>
> compare to TCP sockets, if a TCP bind fails, we know
other programs are<br>
> using the socket ,the ops team then fix the
mis-configured port number,<br>
> change unit or other programs.<br>
> the unix socket should behave similarly.<br>
> the diffrence is when a tcp server is done, the socket
is recycled by<br>
> system, while the unix socket file is left in disk,
which block "unit"'s<br>
> next boot.<br>
> may the idea patch is to unlink the unix socket file
on shutdown,<br>
> instead of startup?<br>
><br>
><br>
> On 2022-04-25 14:38,Scott van Kalken wrote:<br>
> > What if it were a command line option to delete
on start? This way you<br>
> > preserve the existing behaviour while introducing
the desired<br>
> > behaviour. It’s up to the user / admin to decide
if they want to<br>
> > “force delete” as an example.<br>
> ><br>
> > On Mon, 25 Apr 2022 at 4:33 pm, <<a href="mailto:shanlei@asiainfo.com" rel="noreferrer noreferrer noreferrer" target="_blank">shanlei@asiainfo.com</a>>
wrote:<br>
> ><br>
> >> I know the concern, that if we misconfigure
the socket file, other<br>
> >> file<br>
> >> may be deleted accidentally.<br>
> >> But if the program wont delete the file, bind
will fail , that means<br>
> >> we<br>
> >> have to delete the file manually before every
start. that not a good<br>
> >><br>
> >> option to maintain a system.<br>
> >><br>
> >> 在 2022-04-24 18:05,Александр Поволоцкий<br>
> >> wrote:<br>
> >>> Unlink socket that can be in use? I think
it's not a good idea.<br>
> >>><br>
> >>> On 24.04.2022 12:25, <a href="mailto:shanlei@asiainfo.com" rel="noreferrer noreferrer noreferrer" target="_blank">shanlei@asiainfo.com</a>
wrote:<br>
> >>>><br>
> >>>> hello,guys,<br>
> >>>><br>
> >>>> We found if we add a unix socket
listener, the file was left in<br>
> >> disk<br>
> >>>> when unit got shutdown.<br>
> >>>> If the unit starts again and load
configuration from its state<br>
> >> folder,<br>
> >>>> it would fail with error msg "file
exists",<br>
> >>>> so We think the proper process is to
"delete the legacy unix<br>
> >> socket<br>
> >>>> before start", and we present
following patch:<br>
> >>>><br>
> >>>><br>
> >>>> # HG changeset patch<br>
> >>>> # User stdanley <<a href="mailto:shanlei@asiainfo.com" rel="noreferrer noreferrer noreferrer" target="_blank">shanlei@asiainfo.com</a>><br>
> >>>> # Date 1650792235 -28800<br>
> >>>> # Sun Apr 24 17:23:55 2022 +0800<br>
> >>>> # Node ID
29738840c393f12c7d7aa8f3959ed1655b39cd4d<br>
> >>>> # Parent
8e06a879600e83af11345d023c53c2ca445cf82c<br>
> >>>> unlink legacy unix socket file before
binding.<br>
> >>>><br>
> >>>> diff -r 8e06a879600e -r 29738840c393
src/nxt_main_process.c<br>
> >>>> --- a/src/nxt_main_process.c Tue
Apr 12 04:16:00 2022 +0100<br>
> >>>> +++ b/src/nxt_main_process.c Sun
Apr 24 17:23:55 2022 +0800<br>
> >>>> @@ -1142,6 +1142,15 @@<br>
> >>>> }<br>
> >>>><br>
> >>>> #endif<br>
> >>>> +#if (NXT_HAVE_UNIX_DOMAIN)<br>
> >>>> +<br>
> >>>> + if (sa->u.sockaddr.sa_family
== AF_UNIX<br>
> >>>> + && sa->type ==
SOCK_STREAM<br>
> >>>> + &&
sa->u.sockaddr_un.sun_path[0] != '\0') {<br>
> >>>> +<br>
> >>>> + (void)
unlink(sa->u.sockaddr_un.sun_path);<br>
> >>>> +}<br>
> >>>> +#endif<br>
> >>>><br>
> >>>> if (bind(s, &sa->u.sockaddr,
sa->socklen) != 0) {<br>
> >>>> err = nxt_errno;<br>
> >>>>
_______________________________________________<br>
> >>>> unit mailing list -- <a href="mailto:unit@nginx.org" rel="noreferrer noreferrer noreferrer" target="_blank">unit@nginx.org</a><br>
> >>>> To unsubscribe send an email to <a href="mailto:unit-leave@nginx.org" rel="noreferrer noreferrer noreferrer" target="_blank">unit-leave@nginx.org</a><br>
> >>>
_______________________________________________<br>
> >>> unit mailing list -- <a href="mailto:unit@nginx.org" rel="noreferrer noreferrer noreferrer" target="_blank">unit@nginx.org</a><br>
> >>> To unsubscribe send an email to <a href="mailto:unit-leave@nginx.org" rel="noreferrer noreferrer noreferrer" target="_blank">unit-leave@nginx.org</a><br>
> >>
_______________________________________________<br>
> >> unit mailing list -- <a href="mailto:unit@nginx.org" rel="noreferrer noreferrer noreferrer" target="_blank">unit@nginx.org</a><br>
> >> To unsubscribe send an email to <a href="mailto:unit-leave@nginx.org" rel="noreferrer noreferrer noreferrer" target="_blank">unit-leave@nginx.org</a><br>
> > _______________________________________________<br>
> > unit mailing list -- <a href="mailto:unit@nginx.org" rel="noreferrer noreferrer noreferrer" target="_blank">unit@nginx.org</a><br>
> > To unsubscribe send an email to <a href="mailto:unit-leave@nginx.org" rel="noreferrer noreferrer noreferrer" target="_blank">unit-leave@nginx.org</a><br>
><br>
<br>
>_______________________________________________<br>
>unit mailing list -- <a href="mailto:unit@nginx.org" rel="noreferrer noreferrer noreferrer" target="_blank">unit@nginx.org</a><br>
>To unsubscribe send an email to <a href="mailto:unit-leave@nginx.org" rel="noreferrer noreferrer noreferrer" target="_blank">unit-leave@nginx.org</a><br>
<br>
<br>
-- <br>
Cheers,<br>
Oleg A. Mamontov<br>
<br>
mailto: <a href="mailto:oleg@mamontov.net" rel="noreferrer noreferrer noreferrer" target="_blank">oleg@mamontov.net</a><br>
<br>
skype: lonerr11<br>
cell: +7 (903) 798-1352<br>
_______________________________________________<br>
unit mailing list -- <a href="mailto:unit@nginx.org" rel="noreferrer noreferrer noreferrer" target="_blank">unit@nginx.org</a><br>
To unsubscribe send an email to <a href="mailto:unit-leave@nginx.org" rel="noreferrer noreferrer noreferrer" target="_blank">unit-leave@nginx.org</a><br>
</blockquote>
</div>
<br>
<fieldset></fieldset>
<pre>_______________________________________________
unit mailing list -- <a href="mailto:unit@nginx.org" rel="noreferrer noreferrer" target="_blank">unit@nginx.org</a>
To unsubscribe send an email to <a href="mailto:unit-leave@nginx.org" rel="noreferrer noreferrer" target="_blank">unit-leave@nginx.org</a>
</pre>
</blockquote>
</div>
</blockquote></div>
</div>
</blockquote></div></div></div></div>