From shanlei at asiainfo.com Sun Apr 24 09:25:03 2022 From: shanlei at asiainfo.com (shanlei at asiainfo.com) Date: Sun, 24 Apr 2022 17:25:03 +0800 Subject: [PATCH]: unlink legacy unix socket when unit starts Message-ID: hello,guys, We found if we add a unix socket listener, the file was left in disk when unit got shutdown. If the unit starts again and load configuration from its state folder, it would fail with error msg "file exists", so We think the proper process is to "delete the legacy unix socket before start", and we present following patch: # HG changeset patch # User stdanley # Date 1650792235 -28800 # Sun Apr 24 17:23:55 2022 +0800 # Node ID 29738840c393f12c7d7aa8f3959ed1655b39cd4d # Parent 8e06a879600e83af11345d023c53c2ca445cf82c unlink legacy unix socket file before binding. diff -r 8e06a879600e -r 29738840c393 src/nxt_main_process.c --- a/src/nxt_main_process.c Tue Apr 12 04:16:00 2022 +0100 +++ b/src/nxt_main_process.c Sun Apr 24 17:23:55 2022 +0800 @@ -1142,6 +1142,15 @@ } #endif +#if (NXT_HAVE_UNIX_DOMAIN) + + if (sa->u.sockaddr.sa_family == AF_UNIX + && sa->type == SOCK_STREAM + && sa->u.sockaddr_un.sun_path[0] != '\0') { + + (void) unlink(sa->u.sockaddr_un.sun_path); +} +#endif if (bind(s, &sa->u.sockaddr, sa->socklen) != 0) { err = nxt_errno; From tarkhil at over.ru Sun Apr 24 10:05:58 2022 From: tarkhil at over.ru (=?UTF-8?B?0JDQu9C10LrRgdCw0L3QtNGAINCf0L7QstC+0LvQvtGG0LrQuNC5?=) Date: Sun, 24 Apr 2022 13:05:58 +0300 Subject: [PATCH]: unlink legacy unix socket when unit starts In-Reply-To: References: Message-ID: Unlink socket that can be in use? I think it's not a good idea. On 24.04.2022 12:25, shanlei at asiainfo.com wrote: > > hello,guys, > > We found if we add a unix socket listener, the file was left in disk > when unit got shutdown. > If the unit starts again and load configuration from its state folder, > it would fail with error msg "file exists", > so We think the proper process is to "delete the legacy unix socket > before start", and we present following patch: > > > # HG changeset patch > # User stdanley > # Date 1650792235 -28800 > #      Sun Apr 24 17:23:55 2022 +0800 > # Node ID 29738840c393f12c7d7aa8f3959ed1655b39cd4d > # Parent  8e06a879600e83af11345d023c53c2ca445cf82c > unlink legacy unix socket file before binding. > > diff -r 8e06a879600e -r 29738840c393 src/nxt_main_process.c > --- a/src/nxt_main_process.c    Tue Apr 12 04:16:00 2022 +0100 > +++ b/src/nxt_main_process.c    Sun Apr 24 17:23:55 2022 +0800 > @@ -1142,6 +1142,15 @@ >      } > >  #endif > +#if (NXT_HAVE_UNIX_DOMAIN) > + > +    if (sa->u.sockaddr.sa_family == AF_UNIX > +        && sa->type == SOCK_STREAM > +        && sa->u.sockaddr_un.sun_path[0] != '\0') { > + > +        (void) unlink(sa->u.sockaddr_un.sun_path); > +} > +#endif > >      if (bind(s, &sa->u.sockaddr, sa->socklen) != 0) { >          err = nxt_errno; > _______________________________________________ > unit mailing list -- unit at nginx.org > To unsubscribe send an email to unit-leave at nginx.org From shanlei at asiainfo.com Mon Apr 25 06:33:21 2022 From: shanlei at asiainfo.com (shanlei at asiainfo.com) Date: Mon, 25 Apr 2022 14:33:21 +0800 Subject: [PATCH]: unlink legacy unix socket when unit starts In-Reply-To: References: Message-ID: <95ff104c5c17783dee0898b4665be957@asiainfo.com> I know the concern, that if we misconfigure the socket file, other file may be deleted accidentally. But if the program wont delete the file, bind will fail , that means we have to delete the file manually before every start. that not a good option to maintain a system. 在 2022-04-24 18:05,Александр Поволоцкий wrote: > Unlink socket that can be in use? I think it's not a good idea. > > On 24.04.2022 12:25, shanlei at asiainfo.com wrote: >> >> hello,guys, >> >> We found if we add a unix socket listener, the file was left in disk >> when unit got shutdown. >> If the unit starts again and load configuration from its state folder, >> it would fail with error msg "file exists", >> so We think the proper process is to "delete the legacy unix socket >> before start", and we present following patch: >> >> >> # HG changeset patch >> # User stdanley >> # Date 1650792235 -28800 >> #      Sun Apr 24 17:23:55 2022 +0800 >> # Node ID 29738840c393f12c7d7aa8f3959ed1655b39cd4d >> # Parent  8e06a879600e83af11345d023c53c2ca445cf82c >> unlink legacy unix socket file before binding. >> >> diff -r 8e06a879600e -r 29738840c393 src/nxt_main_process.c >> --- a/src/nxt_main_process.c    Tue Apr 12 04:16:00 2022 +0100 >> +++ b/src/nxt_main_process.c    Sun Apr 24 17:23:55 2022 +0800 >> @@ -1142,6 +1142,15 @@ >>      } >> >>  #endif >> +#if (NXT_HAVE_UNIX_DOMAIN) >> + >> +    if (sa->u.sockaddr.sa_family == AF_UNIX >> +        && sa->type == SOCK_STREAM >> +        && sa->u.sockaddr_un.sun_path[0] != '\0') { >> + >> +        (void) unlink(sa->u.sockaddr_un.sun_path); >> +} >> +#endif >> >>      if (bind(s, &sa->u.sockaddr, sa->socklen) != 0) { >>          err = nxt_errno; >> _______________________________________________ >> unit mailing list -- unit at nginx.org >> To unsubscribe send an email to unit-leave at nginx.org > _______________________________________________ > unit mailing list -- unit at nginx.org > To unsubscribe send an email to unit-leave at nginx.org From scottvankalken at gmail.com Mon Apr 25 06:38:41 2022 From: scottvankalken at gmail.com (Scott van Kalken) Date: Mon, 25 Apr 2022 16:38:41 +1000 Subject: [PATCH]: unlink legacy unix socket when unit starts In-Reply-To: <95ff104c5c17783dee0898b4665be957@asiainfo.com> References: <95ff104c5c17783dee0898b4665be957@asiainfo.com> Message-ID: What if it were a command line option to delete on start? This way you preserve the existing behaviour while introducing the desired behaviour. It’s up to the user / admin to decide if they want to “force delete” as an example. On Mon, 25 Apr 2022 at 4:33 pm, wrote: > I know the concern, that if we misconfigure the socket file, other file > may be deleted accidentally. > But if the program wont delete the file, bind will fail , that means we > have to delete the file manually before every start. that not a good > option to maintain a system. > > 在 2022-04-24 18:05,Александр Поволоцкий wrote: > > Unlink socket that can be in use? I think it's not a good idea. > > > > On 24.04.2022 12:25, shanlei at asiainfo.com wrote: > >> > >> hello,guys, > >> > >> We found if we add a unix socket listener, the file was left in disk > >> when unit got shutdown. > >> If the unit starts again and load configuration from its state folder, > >> it would fail with error msg "file exists", > >> so We think the proper process is to "delete the legacy unix socket > >> before start", and we present following patch: > >> > >> > >> # HG changeset patch > >> # User stdanley > >> # Date 1650792235 -28800 > >> # Sun Apr 24 17:23:55 2022 +0800 > >> # Node ID 29738840c393f12c7d7aa8f3959ed1655b39cd4d > >> # Parent 8e06a879600e83af11345d023c53c2ca445cf82c > >> unlink legacy unix socket file before binding. > >> > >> diff -r 8e06a879600e -r 29738840c393 src/nxt_main_process.c > >> --- a/src/nxt_main_process.c Tue Apr 12 04:16:00 2022 +0100 > >> +++ b/src/nxt_main_process.c Sun Apr 24 17:23:55 2022 +0800 > >> @@ -1142,6 +1142,15 @@ > >> } > >> > >> #endif > >> +#if (NXT_HAVE_UNIX_DOMAIN) > >> + > >> + if (sa->u.sockaddr.sa_family == AF_UNIX > >> + && sa->type == SOCK_STREAM > >> + && sa->u.sockaddr_un.sun_path[0] != '\0') { > >> + > >> + (void) unlink(sa->u.sockaddr_un.sun_path); > >> +} > >> +#endif > >> > >> if (bind(s, &sa->u.sockaddr, sa->socklen) != 0) { > >> err = nxt_errno; > >> _______________________________________________ > >> unit mailing list -- unit at nginx.org > >> To unsubscribe send an email to unit-leave at nginx.org > > _______________________________________________ > > unit mailing list -- unit at nginx.org > > To unsubscribe send an email to unit-leave at nginx.org > _______________________________________________ > unit mailing list -- unit at nginx.org > To unsubscribe send an email to unit-leave at nginx.org > -------------- next part -------------- An HTML attachment was scrubbed... URL: From shanlei at asiainfo.com Tue Apr 26 01:50:16 2022 From: shanlei at asiainfo.com (shanlei at asiainfo.com) Date: Tue, 26 Apr 2022 09:50:16 +0800 Subject: [PATCH]: unlink legacy unix socket when unit starts In-Reply-To: References: <95ff104c5c17783dee0898b4665be957@asiainfo.com> Message-ID: <9a4bd8763f964196469c7ba64a8a44d3@asiainfo.com> I have reconsided the situation: compare to TCP sockets, if a TCP bind fails, we know other programs are using the socket ,the ops team then fix the mis-configured port number, change unit or other programs. the unix socket should behave similarly. the diffrence is when a tcp server is done, the socket is recycled by system, while the unix socket file is left in disk, which block "unit"'s next boot. may the idea patch is to unlink the unix socket file on shutdown, instead of startup? On 2022-04-25 14:38,Scott van Kalken wrote: > What if it were a command line option to delete on start? This way you > preserve the existing behaviour while introducing the desired > behaviour. It’s up to the user / admin to decide if they want to > “force delete” as an example. > > On Mon, 25 Apr 2022 at 4:33 pm, wrote: > >> I know the concern, that if we misconfigure the socket file, other >> file >> may be deleted accidentally. >> But if the program wont delete the file, bind will fail , that means >> we >> have to delete the file manually before every start. that not a good >> >> option to maintain a system. >> >> 在 2022-04-24 18:05,Александр Поволоцкий >> wrote: >>> Unlink socket that can be in use? I think it's not a good idea. >>> >>> On 24.04.2022 12:25, shanlei at asiainfo.com wrote: >>>> >>>> hello,guys, >>>> >>>> We found if we add a unix socket listener, the file was left in >> disk >>>> when unit got shutdown. >>>> If the unit starts again and load configuration from its state >> folder, >>>> it would fail with error msg "file exists", >>>> so We think the proper process is to "delete the legacy unix >> socket >>>> before start", and we present following patch: >>>> >>>> >>>> # HG changeset patch >>>> # User stdanley >>>> # Date 1650792235 -28800 >>>> # Sun Apr 24 17:23:55 2022 +0800 >>>> # Node ID 29738840c393f12c7d7aa8f3959ed1655b39cd4d >>>> # Parent 8e06a879600e83af11345d023c53c2ca445cf82c >>>> unlink legacy unix socket file before binding. >>>> >>>> diff -r 8e06a879600e -r 29738840c393 src/nxt_main_process.c >>>> --- a/src/nxt_main_process.c Tue Apr 12 04:16:00 2022 +0100 >>>> +++ b/src/nxt_main_process.c Sun Apr 24 17:23:55 2022 +0800 >>>> @@ -1142,6 +1142,15 @@ >>>> } >>>> >>>> #endif >>>> +#if (NXT_HAVE_UNIX_DOMAIN) >>>> + >>>> + if (sa->u.sockaddr.sa_family == AF_UNIX >>>> + && sa->type == SOCK_STREAM >>>> + && sa->u.sockaddr_un.sun_path[0] != '\0') { >>>> + >>>> + (void) unlink(sa->u.sockaddr_un.sun_path); >>>> +} >>>> +#endif >>>> >>>> if (bind(s, &sa->u.sockaddr, sa->socklen) != 0) { >>>> err = nxt_errno; >>>> _______________________________________________ >>>> unit mailing list -- unit at nginx.org >>>> To unsubscribe send an email to unit-leave at nginx.org >>> _______________________________________________ >>> unit mailing list -- unit at nginx.org >>> To unsubscribe send an email to unit-leave at nginx.org >> _______________________________________________ >> unit mailing list -- unit at nginx.org >> To unsubscribe send an email to unit-leave at nginx.org > _______________________________________________ > unit mailing list -- unit at nginx.org > To unsubscribe send an email to unit-leave at nginx.org From scottvankalken at gmail.com Tue Apr 26 19:11:26 2022 From: scottvankalken at gmail.com (Scott van Kalken) Date: Wed, 27 Apr 2022 05:11:26 +1000 Subject: [PATCH]: unlink legacy unix socket when unit starts In-Reply-To: <9a4bd8763f964196469c7ba64a8a44d3@asiainfo.com> References: <95ff104c5c17783dee0898b4665be957@asiainfo.com> <9a4bd8763f964196469c7ba64a8a44d3@asiainfo.com> Message-ID: This will work well for cases where unit shuts down gracefully. If unit does not shut down gracefully, then i think you will have the same startup problem. It’s a good point about the TCP socket. On Tue, 26 Apr 2022 at 11:50 am, wrote: > I have reconsided the situation: > compare to TCP sockets, if a TCP bind fails, we know other programs are > using the socket ,the ops team then fix the mis-configured port number, > change unit or other programs. > the unix socket should behave similarly. > the diffrence is when a tcp server is done, the socket is recycled by > system, while the unix socket file is left in disk, which block "unit"'s > next boot. > may the idea patch is to unlink the unix socket file on shutdown, > instead of startup? > > > On 2022-04-25 14:38,Scott van Kalken wrote: > > What if it were a command line option to delete on start? This way you > > preserve the existing behaviour while introducing the desired > > behaviour. It’s up to the user / admin to decide if they want to > > “force delete” as an example. > > > > On Mon, 25 Apr 2022 at 4:33 pm, wrote: > > > >> I know the concern, that if we misconfigure the socket file, other > >> file > >> may be deleted accidentally. > >> But if the program wont delete the file, bind will fail , that means > >> we > >> have to delete the file manually before every start. that not a good > >> > >> option to maintain a system. > >> > >> 在 2022-04-24 18:05,Александр Поволоцкий > >> wrote: > >>> Unlink socket that can be in use? I think it's not a good idea. > >>> > >>> On 24.04.2022 12:25, shanlei at asiainfo.com wrote: > >>>> > >>>> hello,guys, > >>>> > >>>> We found if we add a unix socket listener, the file was left in > >> disk > >>>> when unit got shutdown. > >>>> If the unit starts again and load configuration from its state > >> folder, > >>>> it would fail with error msg "file exists", > >>>> so We think the proper process is to "delete the legacy unix > >> socket > >>>> before start", and we present following patch: > >>>> > >>>> > >>>> # HG changeset patch > >>>> # User stdanley > >>>> # Date 1650792235 -28800 > >>>> # Sun Apr 24 17:23:55 2022 +0800 > >>>> # Node ID 29738840c393f12c7d7aa8f3959ed1655b39cd4d > >>>> # Parent 8e06a879600e83af11345d023c53c2ca445cf82c > >>>> unlink legacy unix socket file before binding. > >>>> > >>>> diff -r 8e06a879600e -r 29738840c393 src/nxt_main_process.c > >>>> --- a/src/nxt_main_process.c Tue Apr 12 04:16:00 2022 +0100 > >>>> +++ b/src/nxt_main_process.c Sun Apr 24 17:23:55 2022 +0800 > >>>> @@ -1142,6 +1142,15 @@ > >>>> } > >>>> > >>>> #endif > >>>> +#if (NXT_HAVE_UNIX_DOMAIN) > >>>> + > >>>> + if (sa->u.sockaddr.sa_family == AF_UNIX > >>>> + && sa->type == SOCK_STREAM > >>>> + && sa->u.sockaddr_un.sun_path[0] != '\0') { > >>>> + > >>>> + (void) unlink(sa->u.sockaddr_un.sun_path); > >>>> +} > >>>> +#endif > >>>> > >>>> if (bind(s, &sa->u.sockaddr, sa->socklen) != 0) { > >>>> err = nxt_errno; > >>>> _______________________________________________ > >>>> unit mailing list -- unit at nginx.org > >>>> To unsubscribe send an email to unit-leave at nginx.org > >>> _______________________________________________ > >>> unit mailing list -- unit at nginx.org > >>> To unsubscribe send an email to unit-leave at nginx.org > >> _______________________________________________ > >> unit mailing list -- unit at nginx.org > >> To unsubscribe send an email to unit-leave at nginx.org > > _______________________________________________ > > unit mailing list -- unit at nginx.org > > To unsubscribe send an email to unit-leave at nginx.org > -------------- next part -------------- An HTML attachment was scrubbed... URL: From oleg at mamontov.net Tue Apr 26 21:45:10 2022 From: oleg at mamontov.net (Oleg A. Mamontov) Date: Wed, 27 Apr 2022 00:45:10 +0300 Subject: [PATCH]: unlink legacy unix socket when unit starts In-Reply-To: References: <95ff104c5c17783dee0898b4665be957@asiainfo.com> <9a4bd8763f964196469c7ba64a8a44d3@asiainfo.com> Message-ID: <20220426214510.cuwucvv7hgx42m6n@xenon.mamontov.net> On Wed, Apr 27, 2022 at 05:11:26AM +1000, Scott van Kalken wrote: >This will work well for cases where unit shuts down gracefully. If unit does >not shut down gracefully, then i think you will have the same startup problem.  > >It’s a good point about the TCP socket.  It seems the key point is the way to check on startup whether the unix socket is stale or currently in use and then to decide remove it and re-create or just fail the start, isn't it? >On Tue, 26 Apr 2022 at 11:50 am, wrote: > > I have reconsided the situation: > compare to TCP sockets, if a TCP bind fails, we know other programs are > using the socket ,the ops team then fix the mis-configured port number, > change unit or other programs. > the unix socket should behave similarly. > the diffrence is when a tcp server is done, the socket is recycled by > system, while the unix socket file is left in disk, which block "unit"'s > next boot. > may the idea patch is to unlink the unix socket file on shutdown, > instead of startup? > > > On 2022-04-25 14:38,Scott van Kalken wrote: > > What if it were a command line option to delete on start? This way you > > preserve the existing behaviour while introducing the desired > > behaviour. It’s up to the user / admin to decide if they want to > > “force delete” as an example. > > > > On Mon, 25 Apr 2022 at 4:33 pm, wrote: > > > >> I know the concern, that if we misconfigure the socket file, other > >> file > >> may be deleted accidentally. > >> But if the program wont delete the file, bind will fail , that means > >> we > >> have to delete the file manually before every start. that not a good > >> > >> option to maintain a system. > >> > >> 在 2022-04-24 18:05,Александр Поволоцкий > >> wrote: > >>> Unlink socket that can be in use? I think it's not a good idea. > >>> > >>> On 24.04.2022 12:25, shanlei at asiainfo.com wrote: > >>>> > >>>> hello,guys, > >>>> > >>>> We found if we add a unix socket listener, the file was left in > >> disk > >>>> when unit got shutdown. > >>>> If the unit starts again and load configuration from its state > >> folder, > >>>> it would fail with error msg "file exists", > >>>> so We think the proper process is to "delete the legacy unix > >> socket > >>>> before start", and we present following patch: > >>>> > >>>> > >>>> # HG changeset patch > >>>> # User stdanley > >>>> # Date 1650792235 -28800 > >>>> #      Sun Apr 24 17:23:55 2022 +0800 > >>>> # Node ID 29738840c393f12c7d7aa8f3959ed1655b39cd4d > >>>> # Parent  8e06a879600e83af11345d023c53c2ca445cf82c > >>>> unlink legacy unix socket file before binding. > >>>> > >>>> diff -r 8e06a879600e -r 29738840c393 src/nxt_main_process.c > >>>> --- a/src/nxt_main_process.c    Tue Apr 12 04:16:00 2022 +0100 > >>>> +++ b/src/nxt_main_process.c    Sun Apr 24 17:23:55 2022 +0800 > >>>> @@ -1142,6 +1142,15 @@ > >>>> } > >>>> > >>>> #endif > >>>> +#if (NXT_HAVE_UNIX_DOMAIN) > >>>> + > >>>> +    if (sa->u.sockaddr.sa_family == AF_UNIX > >>>> +        && sa->type == SOCK_STREAM > >>>> +        && sa->u.sockaddr_un.sun_path[0] != '\0') { > >>>> + > >>>> +        (void) unlink(sa->u.sockaddr_un.sun_path); > >>>> +} > >>>> +#endif > >>>> > >>>> if (bind(s, &sa->u.sockaddr, sa->socklen) != 0) { > >>>> err = nxt_errno; > >>>> _______________________________________________ > >>>> unit mailing list -- unit at nginx.org > >>>> To unsubscribe send an email to unit-leave at nginx.org > >>> _______________________________________________ > >>> unit mailing list -- unit at nginx.org > >>> To unsubscribe send an email to unit-leave at nginx.org > >> _______________________________________________ > >> unit mailing list -- unit at nginx.org > >> To unsubscribe send an email to unit-leave at nginx.org > > _______________________________________________ > > unit mailing list -- unit at nginx.org > > To unsubscribe send an email to unit-leave at nginx.org > >_______________________________________________ >unit mailing list -- unit at nginx.org >To unsubscribe send an email to unit-leave at nginx.org -- Cheers, Oleg A. Mamontov mailto: oleg at mamontov.net skype: lonerr11 cell: +7 (903) 798-1352 From shanlei at asiainfo.com Fri Apr 29 05:34:44 2022 From: shanlei at asiainfo.com (lei shan) Date: Fri, 29 Apr 2022 13:34:44 +0800 Subject: [PATCH]: unlink legacy unix socket when unit starts In-Reply-To: <20220426214510.cuwucvv7hgx42m6n@xenon.mamontov.net> References: <95ff104c5c17783dee0898b4665be957@asiainfo.com> <9a4bd8763f964196469c7ba64a8a44d3@asiainfo.com> <20220426214510.cuwucvv7hgx42m6n@xenon.mamontov.net> Message-ID: Hello guys, The process may crash, or other may misconfig and cause the file confliction. But at least, unit should remove the pipe file on exit,as it already does to the control pipe. So a patch should remove the Unix pipe on stop , instead of on startup. Can we agree on this? Thanks & Best Regards On Wed, 27 Apr 2022, 05:45 Oleg A. Mamontov, wrote: > On Wed, Apr 27, 2022 at 05:11:26AM +1000, Scott van Kalken wrote: > >This will work well for cases where unit shuts down gracefully. If unit > does > >not shut down gracefully, then i think you will have the same startup > problem. > > > >It’s a good point about the TCP socket. > > It seems the key point is the way to check on startup whether the unix > socket is stale or currently in use and then to decide remove it and > re-create or just fail the start, isn't it? > > >On Tue, 26 Apr 2022 at 11:50 am, wrote: > > > > I have reconsided the situation: > > compare to TCP sockets, if a TCP bind fails, we know other programs > are > > using the socket ,the ops team then fix the mis-configured port > number, > > change unit or other programs. > > the unix socket should behave similarly. > > the diffrence is when a tcp server is done, the socket is recycled by > > system, while the unix socket file is left in disk, which block > "unit"'s > > next boot. > > may the idea patch is to unlink the unix socket file on shutdown, > > instead of startup? > > > > > > On 2022-04-25 14:38,Scott van Kalken wrote: > > > What if it were a command line option to delete on start? This way > you > > > preserve the existing behaviour while introducing the desired > > > behaviour. It’s up to the user / admin to decide if they want to > > > “force delete” as an example. > > > > > > On Mon, 25 Apr 2022 at 4:33 pm, wrote: > > > > > >> I know the concern, that if we misconfigure the socket file, other > > >> file > > >> may be deleted accidentally. > > >> But if the program wont delete the file, bind will fail , that > means > > >> we > > >> have to delete the file manually before every start. that not a > good > > >> > > >> option to maintain a system. > > >> > > >> 在 2022-04-24 18:05,Александр Поволоцкий > > >> wrote: > > >>> Unlink socket that can be in use? I think it's not a good idea. > > >>> > > >>> On 24.04.2022 12:25, shanlei at asiainfo.com wrote: > > >>>> > > >>>> hello,guys, > > >>>> > > >>>> We found if we add a unix socket listener, the file was left in > > >> disk > > >>>> when unit got shutdown. > > >>>> If the unit starts again and load configuration from its state > > >> folder, > > >>>> it would fail with error msg "file exists", > > >>>> so We think the proper process is to "delete the legacy unix > > >> socket > > >>>> before start", and we present following patch: > > >>>> > > >>>> > > >>>> # HG changeset patch > > >>>> # User stdanley > > >>>> # Date 1650792235 -28800 > > >>>> # Sun Apr 24 17:23:55 2022 +0800 > > >>>> # Node ID 29738840c393f12c7d7aa8f3959ed1655b39cd4d > > >>>> # Parent 8e06a879600e83af11345d023c53c2ca445cf82c > > >>>> unlink legacy unix socket file before binding. > > >>>> > > >>>> diff -r 8e06a879600e -r 29738840c393 src/nxt_main_process.c > > >>>> --- a/src/nxt_main_process.c Tue Apr 12 04:16:00 2022 +0100 > > >>>> +++ b/src/nxt_main_process.c Sun Apr 24 17:23:55 2022 +0800 > > >>>> @@ -1142,6 +1142,15 @@ > > >>>> } > > >>>> > > >>>> #endif > > >>>> +#if (NXT_HAVE_UNIX_DOMAIN) > > >>>> + > > >>>> + if (sa->u.sockaddr.sa_family == AF_UNIX > > >>>> + && sa->type == SOCK_STREAM > > >>>> + && sa->u.sockaddr_un.sun_path[0] != '\0') { > > >>>> + > > >>>> + (void) unlink(sa->u.sockaddr_un.sun_path); > > >>>> +} > > >>>> +#endif > > >>>> > > >>>> if (bind(s, &sa->u.sockaddr, sa->socklen) != 0) { > > >>>> err = nxt_errno; > > >>>> _______________________________________________ > > >>>> unit mailing list -- unit at nginx.org > > >>>> To unsubscribe send an email to unit-leave at nginx.org > > >>> _______________________________________________ > > >>> unit mailing list -- unit at nginx.org > > >>> To unsubscribe send an email to unit-leave at nginx.org > > >> _______________________________________________ > > >> unit mailing list -- unit at nginx.org > > >> To unsubscribe send an email to unit-leave at nginx.org > > > _______________________________________________ > > > unit mailing list -- unit at nginx.org > > > To unsubscribe send an email to unit-leave at nginx.org > > > > >_______________________________________________ > >unit mailing list -- unit at nginx.org > >To unsubscribe send an email to unit-leave at nginx.org > > > -- > Cheers, > Oleg A. Mamontov > > mailto: oleg at mamontov.net > > skype: lonerr11 > cell: +7 (903) 798-1352 > _______________________________________________ > unit mailing list -- unit at nginx.org > To unsubscribe send an email to unit-leave at nginx.org > -------------- next part -------------- An HTML attachment was scrubbed... URL: From shanlei at asiainfo.com Fri Apr 29 08:37:22 2022 From: shanlei at asiainfo.com (lei shan) Date: Fri, 29 Apr 2022 16:37:22 +0800 Subject: Fwd: [PATCH]: unlink legacy unix socket when unit starts In-Reply-To: References: <95ff104c5c17783dee0898b4665be957@asiainfo.com> <9a4bd8763f964196469c7ba64a8a44d3@asiainfo.com> <20220426214510.cuwucvv7hgx42m6n@xenon.mamontov.net> Message-ID: ---------- Forwarded message --------- From: lei shan Date: Fri, 29 Apr 2022, 16:36 Subject: Re: [PATCH]: unlink legacy unix socket when unit starts To: Александр Поволоцкий I am working on it, just as control socket did. 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. The cleaning can't be done by router is : The Unix socket owned by root user On Fri, 29 Apr 2022, 14:09 Александр Поволоцкий, wrote: > No patch will remove pipe on kill -9. We need to implement the logic used > for control socket. > On 29.04.2022 8:34, lei shan wrote: > > Hello guys, > > The process may crash, or other may misconfig and cause the file > confliction. > But at least, unit should remove the pipe file on exit,as it already does > to the control pipe. > > So a patch should remove the Unix pipe on stop , instead of on startup. > > Can we agree on this? > > Thanks & Best Regards > > > On Wed, 27 Apr 2022, 05:45 Oleg A. Mamontov, wrote: > >> On Wed, Apr 27, 2022 at 05:11:26AM +1000, Scott van Kalken wrote: >> >This will work well for cases where unit shuts down gracefully. If unit >> does >> >not shut down gracefully, then i think you will have the same startup >> problem. >> > >> >It’s a good point about the TCP socket. >> >> It seems the key point is the way to check on startup whether the unix >> socket is stale or currently in use and then to decide remove it and >> re-create or just fail the start, isn't it? >> >> >On Tue, 26 Apr 2022 at 11:50 am, wrote: >> > >> > I have reconsided the situation: >> > compare to TCP sockets, if a TCP bind fails, we know other programs >> are >> > using the socket ,the ops team then fix the mis-configured port >> number, >> > change unit or other programs. >> > the unix socket should behave similarly. >> > the diffrence is when a tcp server is done, the socket is recycled by >> > system, while the unix socket file is left in disk, which block >> "unit"'s >> > next boot. >> > may the idea patch is to unlink the unix socket file on shutdown, >> > instead of startup? >> > >> > >> > On 2022-04-25 14:38,Scott van Kalken wrote: >> > > What if it were a command line option to delete on start? This way >> you >> > > preserve the existing behaviour while introducing the desired >> > > behaviour. It’s up to the user / admin to decide if they want to >> > > “force delete” as an example. >> > > >> > > On Mon, 25 Apr 2022 at 4:33 pm, wrote: >> > > >> > >> I know the concern, that if we misconfigure the socket file, other >> > >> file >> > >> may be deleted accidentally. >> > >> But if the program wont delete the file, bind will fail , that >> means >> > >> we >> > >> have to delete the file manually before every start. that not a >> good >> > >> >> > >> option to maintain a system. >> > >> >> > >> 在 2022-04-24 18:05,Александр Поволоцкий >> > >> wrote: >> > >>> Unlink socket that can be in use? I think it's not a good idea. >> > >>> >> > >>> On 24.04.2022 12:25, shanlei at asiainfo.com wrote: >> > >>>> >> > >>>> hello,guys, >> > >>>> >> > >>>> We found if we add a unix socket listener, the file was left in >> > >> disk >> > >>>> when unit got shutdown. >> > >>>> If the unit starts again and load configuration from its state >> > >> folder, >> > >>>> it would fail with error msg "file exists", >> > >>>> so We think the proper process is to "delete the legacy unix >> > >> socket >> > >>>> before start", and we present following patch: >> > >>>> >> > >>>> >> > >>>> # HG changeset patch >> > >>>> # User stdanley >> > >>>> # Date 1650792235 -28800 >> > >>>> # Sun Apr 24 17:23:55 2022 +0800 >> > >>>> # Node ID 29738840c393f12c7d7aa8f3959ed1655b39cd4d >> > >>>> # Parent 8e06a879600e83af11345d023c53c2ca445cf82c >> > >>>> unlink legacy unix socket file before binding. >> > >>>> >> > >>>> diff -r 8e06a879600e -r 29738840c393 src/nxt_main_process.c >> > >>>> --- a/src/nxt_main_process.c Tue Apr 12 04:16:00 2022 +0100 >> > >>>> +++ b/src/nxt_main_process.c Sun Apr 24 17:23:55 2022 +0800 >> > >>>> @@ -1142,6 +1142,15 @@ >> > >>>> } >> > >>>> >> > >>>> #endif >> > >>>> +#if (NXT_HAVE_UNIX_DOMAIN) >> > >>>> + >> > >>>> + if (sa->u.sockaddr.sa_family == AF_UNIX >> > >>>> + && sa->type == SOCK_STREAM >> > >>>> + && sa->u.sockaddr_un.sun_path[0] != '\0') { >> > >>>> + >> > >>>> + (void) unlink(sa->u.sockaddr_un.sun_path); >> > >>>> +} >> > >>>> +#endif >> > >>>> >> > >>>> if (bind(s, &sa->u.sockaddr, sa->socklen) != 0) { >> > >>>> err = nxt_errno; >> > >>>> _______________________________________________ >> > >>>> unit mailing list -- unit at nginx.org >> > >>>> To unsubscribe send an email to unit-leave at nginx.org >> > >>> _______________________________________________ >> > >>> unit mailing list -- unit at nginx.org >> > >>> To unsubscribe send an email to unit-leave at nginx.org >> > >> _______________________________________________ >> > >> unit mailing list -- unit at nginx.org >> > >> To unsubscribe send an email to unit-leave at nginx.org >> > > _______________________________________________ >> > > unit mailing list -- unit at nginx.org >> > > To unsubscribe send an email to unit-leave at nginx.org >> > >> >> >_______________________________________________ >> >unit mailing list -- unit at nginx.org >> >To unsubscribe send an email to unit-leave at nginx.org >> >> >> -- >> Cheers, >> Oleg A. Mamontov >> >> mailto: oleg at mamontov.net >> >> skype: lonerr11 >> cell: +7 (903) 798-1352 >> _______________________________________________ >> unit mailing list -- unit at nginx.org >> To unsubscribe send an email to unit-leave at nginx.org >> > > _______________________________________________ > unit mailing list -- unit at nginx.org > To unsubscribe send an email to unit-leave at nginx.org > > -------------- next part -------------- An HTML attachment was scrubbed... URL: