Live data from Hacker News

Tokio and Prctl = Nasty Bug

kobzol.github.io

51–60 of 78 posts

Re: Tokio and Prctl = Nasty Bug

#51
Although we will need to add one additional unsafe block once we migrate to the 2024 edition because we use std::env::set_var in main :laughing:

This is unsafe rightfully and should not be used without checking. It's just undefined behavior when using threads as it's not threadsafe. https://ttimo.typepad.com/blog/2024/11/the-steam-client-upda...

Re: Tokio and Prctl = Nasty Bug

#52

Seeing the first mention of 10 seconds, I thought (jokingly) - Why not grep the source for the 10 second value. Jokingly, because I thought it would be an emergent property, not a literal value. Turns out it was a literal value after all and grepping would have helped!

There was no mention of a ten second interval anywhere in the code, only in the tests they wrote while debugging.

Re: Tokio and Prctl = Nasty Bug

#53

Seeing the first mention of 10 seconds, I thought (jokingly) - Why not grep the source for the 10 second value. Jokingly, because I thought it would be an emergent property, not a literal value. Turns out it was a literal value after all and grepping would have helped!

There was no mention of a ten second interval anywhere in the code, only in the tests they wrote while debugging.

As mentioned in the article, there is a 10 second value in Tokio - the default thread timeout.

Re: Tokio and Prctl = Nasty Bug

#54
post #9

I may be mistaken, but I believe the bug still exists, but in a more esoteric manner; and a future change might cause the bug to exist again. The author might want to warn against usage of `tokio::task::block_in_place`, if the underlying issue can't be fixed. The reason the current approach works is it runs on tokio's worker threads, which last the lifetime of the tokio runtime. However, if `tokio::task::block_in_pla…

My knowledge isn't very good here, but I assumed since they're using the single thread executor, everything was being spawned on the main thread. The only time new (temporary) threads were created was when calling `spawn_blocking`. And the main thread can't be moved because it's part of the `main()` call stack? Maybe...

[deleted]

Re: Tokio and Prctl = Nasty Bug

#55
post #44
post #33

Earlier quoted context omitted.

It is sadly not propagated to grandchildren. I tries the subreaper approach, but it doesn't help. The children are reparented to the worker, but when the worker dies, they are then just reparented to init, like normally.

You also need to specifically have the subreaper process call the "wait" syscall, and wait for all children, otherwise of course they'll end up reparented to init. If you want to write a process manager, one of the process manager's responsibilities is waiting on its children.

Just a nitpick: They don’t get reparented to init regardless of whether you call wait or not, so long as the parent process exists. They’ll be in a zombie state waiting to be reaped via a parent call to wait. Only if the parent dies/exits without reaping will they be reparented to init.

Re: Tokio and Prctl = Nasty Bug

#56
post #27

Earlier quoted context omitted.

I wonder if this is difference between libc fork (which calls clone syscall) and kernel fork syscall.

No, it isn’t. Neither glibc fork nor kernel fork syscall provide any special handling for PDEATHSIG beyond what clone syscall does.

Yeah, I misremembered/misread and didn't check. Bleh.

(The article sets it after forking.)

Re: Tokio and Prctl = Nasty Bug

#57
A similar issue in Go, that I've encountered in real code: https://github.com/golang/go/issues/27505#issuecomment-71370...

In a nutshell, if you want to use the death signal, which is very handy and useful, you also need to lock an OS thread so that it can't be destroyed. Fortunately I'm only spawning one process so I don't need to jump through hoops, I can just dedicate a thread to it, but it would be inconvenient to want to spawn lots of processes that way.

Speaking more generally, a lot of things that I learned in the 200xs apply to "processes", and things I just osmosed over the years as applying to "processes", were changed to apply to "threads" over the decades and a lot of people have not noticed that, even now. Even though I know this, my mental model of what is associated to a thread and what is associated to a process is quite weak, since I've not yet needed to acquire a deep understanding. In general I would suggest to people that if you are dealing with this sort of system programming that you at least keep this general idea in your head so that the thought pops up that if you're having trouble, it may be related to your internal beliefs that things related to "processes" are actually related to "threads" and in fact just because you did something like set a UID or something somewhere in your code doesn't necessarily mean that that UID will be in effect somewhere else.

Re: Tokio and Prctl = Nasty Bug

#58
> In particular, it is not always possible for HQ to ensure that when a process that spawns tasks (called worker) quits unexpectedly (e.g. when it receives SIGKILL), its spawned tasks will be cleaned up.

I have no clue about HyperQueue architecture, but is this really a problem? Normally if the main process of service exits then systemd will clean up the children. Why does HyperQueue need to implement it's own cleanup?

Re: Tokio and Prctl = Nasty Bug

#59
post #24

Earlier quoted context omitted.

There's been no fundamental change in the kernel level representation of pthreads, they are still clone()d processes with just some sharing flags set differently that eg affect how PIDs work.

More precisely, distinguishing a process and a thread is a pointless overspecification. Unfortunately POSIX mandates it and glibc accepts it. If you want to register per-thread signal handlers you're forced to step outside the bounds of glibc and pthreads which I think is quite unfortunate.

Linux isn't the only kernel in the world. Posix needs to be kernel agnostic. Also need common abstractions to have unique names.
Post reply on HN