During my testing using Alex's playground scripts, I noticed that when
we restart `linkd` for a seed without changing profile, it fails
due to an error: "Address already in use". This is caused by binding
to UNIX sockets that already exist.
This patch is to unlink the UNIX sockets before binding. If the UNIX
sockets did not exists, it will be no-op.
I tested with the diff and no longer see these errors.
Han Xu (1):
unlink unix socket before bind
cli/linkd-lib/src/api/sockets.rs | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
--
2.32.0 (Apple Git-132)
[PATCH radicle-link v1 1/1] unlink unix socket before bind
It would be nice to get rid of the signal handles, unix sockets etc.
Doesn't make it much portable I mean... ?
Can't we just link to git2-rs instead of running all these pipes ?
------- Original Message -------
On Friday, August 12th, 2022 at 9:16 PM, Fintan Halpenny <fintan.halpenny@gmail.com> wrote:
> LGTM> > I'll just note that this is being caused by gitoxide under the hood> due to some signal handler shenanigans.
On 12/08/22 12:16pm, Fintan Halpenny wrote:
> LGTM>> I'll just note that this is being caused by gitoxide under the hood> due to some signal handler shenanigans.
I think we should fix that in this patch. The problem is that gitoxide
intercepts signals. We just need to turn that off. This is just a
question of adding the following line to the start of the `main`
function:
git_tempfile::force_setup(git_tempfile::SignalHandlerMode::None);
On 12/08/22 11:19am, MissM_signed@protonmail.ch wrote:
> It would be nice to get rid of the signal handles, unix sockets etc.>> Doesn't make it much portable I mean... ?
It's not really intended to be portable though. Windows doesn't have
socket activation and so an alternative approach will probably be needed
anyway.
>> Can't we just link to git2-rs instead of running all these pipes ?
What do you mean by this?
On Fri, Aug 12, 2022 at 5:09 AM Alex Good <alex@memoryandthought.me> wrote:
>> On 12/08/22 12:16pm, Fintan Halpenny wrote:> > LGTM> >> > I'll just note that this is being caused by gitoxide under the hood> > due to some signal handler shenanigans.
How does the signal handler impact the UNIX sockets created in
`linkd-lib` node start ?
>> I think we should fix that in this patch. The problem is that gitoxide> intercepts signals. We just need to turn that off. This is just a> question of adding the following line to the start of the `main`> function:>> git_tempfile::force_setup(git_tempfile::SignalHandlerMode::None);
Does it mean that if we don't have these signal handler, the node will
never use the UNIX sockets?
thanks
Han
On 15/08/22 08:57am, Han wrote:
> On Fri, Aug 12, 2022 at 5:09 AM Alex Good <alex@memoryandthought.me> wrote:> >> > On 12/08/22 12:16pm, Fintan Halpenny wrote:> > > LGTM> > >> > > I'll just note that this is being caused by gitoxide under the hood> > > due to some signal handler shenanigans.>> How does the signal handler impact the UNIX sockets created in> `linkd-lib` node start ?
Gitoxide installs a signal handler which pre-empts the signal handlers
`linkd-lib` installs to unlink the sockets when the application is
killed.
>> >> > I think we should fix that in this patch. The problem is that gitoxide> > intercepts signals. We just need to turn that off. This is just a> > question of adding the following line to the start of the `main`> > function:> >> > git_tempfile::force_setup(git_tempfile::SignalHandlerMode::None);>> Does it mean that if we don't have these signal handler, the node will> never use the UNIX sockets?
No not at all. The unix sockets are used to expose an RPC which local
applications can use to interface with `linkd`.
On Mon, Aug 15, 2022 at 9:19 AM Alex Good <alex@memoryandthought.me> wrote:
>> On 15/08/22 08:57am, Han wrote:> > On Fri, Aug 12, 2022 at 5:09 AM Alex Good <alex@memoryandthought.me> wrote:> > >> > > On 12/08/22 12:16pm, Fintan Halpenny wrote:> > > > LGTM> > > >> > > > I'll just note that this is being caused by gitoxide under the hood> > > > due to some signal handler shenanigans.> >> > How does the signal handler impact the UNIX sockets created in> > `linkd-lib` node start ?>> Gitoxide installs a signal handler which pre-empts the signal handlers> `linkd-lib` installs to unlink the sockets when the application is> killed.
I probably missed this. "git grep unlink" didn't show any other unlink
calls except the ones I've added. Probably using a different
syscall/function?
>> >> > >> > > I think we should fix that in this patch. The problem is that gitoxide> > > intercepts signals. We just need to turn that off. This is just a> > > question of adding the following line to the start of the `main`> > > function:> > >> > > git_tempfile::force_setup(git_tempfile::SignalHandlerMode::None);> >> > Does it mean that if we don't have these signal handler, the node will> > never use the UNIX sockets?>> No not at all. The unix sockets are used to expose an RPC which local> applications can use to interface with `linkd`.
Make sense. I will add the line you mentioned. (btw, it seems that
git_tempfile has "setup()", not "force_setup()").
Thanks!
Han
On 15/08/22 10:07am, Han wrote:
> On Mon, Aug 15, 2022 at 9:19 AM Alex Good <alex@memoryandthought.me> wrote:> >> > On 15/08/22 08:57am, Han wrote:> > > On Fri, Aug 12, 2022 at 5:09 AM Alex Good <alex@memoryandthought.me> wrote:> > > >> > > > On 12/08/22 12:16pm, Fintan Halpenny wrote:> > > > > LGTM> > > > >> > > > > I'll just note that this is being caused by gitoxide under the hood> > > > > due to some signal handler shenanigans.> > >> > > How does the signal handler impact the UNIX sockets created in> > > `linkd-lib` node start ?> >> > Gitoxide installs a signal handler which pre-empts the signal handlers> > `linkd-lib` installs to unlink the sockets when the application is> > killed.>> I probably missed this. "git grep unlink" didn't show any other unlink> calls except the ones I've added. Probably using a different> syscall/function?
The relevant code is in `linkd-lib/src/api/sockets.rs:53` in the
`cleanup` function.
>> >> > >> > > >> > > > I think we should fix that in this patch. The problem is that gitoxide> > > > intercepts signals. We just need to turn that off. This is just a> > > > question of adding the following line to the start of the `main`> > > > function:> > > >> > > > git_tempfile::force_setup(git_tempfile::SignalHandlerMode::None);> > >> > > Does it mean that if we don't have these signal handler, the node will> > > never use the UNIX sockets?> >> > No not at all. The unix sockets are used to expose an RPC which local> > applications can use to interface with `linkd`.>> Make sense. I will add the line you mentioned. (btw, it seems that> git_tempfile has "setup()", not "force_setup()").
You might be looking at the wrong version. The version we are depending
on is (I think) 1.0.6.
[PATCH radicle-link v2 0/2] UNIX socket cleanup and unlink
Thanks for your comments for the v1 patch. I've added a line in `linkd`
main to disable the signal handlers from gitoxide.
I've kept the `unlink` calls before socket bind so that regardless the
signal handling results we can always proceed with the bindings.
Here is a test log of the signal handler part: (press ctrl-c)
2022-08-16T13:33:59.101456Z INFO linkd_lib::signals: received
termination signal, signal: SignalKind(2)
at /home/pi/work/radicle-link/cli/linkd-lib/src/signals.rs:24
in linkd_lib::signals::signals subroutine
2022-08-16T13:33:59.102090Z INFO linkd_lib::api::sockets: Sockets::cleanup
at /home/pi/work/radicle-link/cli/linkd-lib/src/api/sockets.rs:54
2022-08-16T13:33:59.102293Z INFO linkd_lib::protocol: network
endpoint shut down
at /home/pi/work/radicle-link/cli/linkd-lib/src/protocol.rs:48
in linkd_lib::protocol::protocol subroutine
Han Xu (2):
unlink unix socket before bind
disable gitoxide signle handlers in linkd
bins/Cargo.lock | 1 +
bins/linkd/Cargo.toml | 3 +++
bins/linkd/src/main.rs | 2 ++
cli/linkd-lib/src/api/sockets.rs | 16 ++++++++++++++--
4 files changed, 20 insertions(+), 2 deletions(-)
--
2.32.0 (Apple Git-132)
[PATCH radicle-link v2 1/2] unlink unix socket before bind
Thanks Fintan. Let me know if I need to do anything else for this
patch as I'm new to the process.
Han
On Tue, Aug 16, 2022 at 8:29 AM Fintan Halpenny
<fintan.halpenny@gmail.com> wrote:
>> I'm happy with this :)
Re: [PATCH radicle-link v2 0/2] UNIX socket cleanup and unlink