|
|
Log in / Subscribe / Register

Changing Fedora's shutdown timeouts

Changing Fedora's shutdown timeouts

Posted Jan 18, 2023 23:48 UTC (Wed) by flussence (guest, #85566)
Parent article: Changing Fedora's shutdown timeouts

This smells like premature optimization based on reading tea leaves and vibes, and a great way to make anyone running a large RDBMS side-eye any distro based on Fedora. And I say that as a runit user where the default is 7 seconds!

There is one way to do it right: *profile* the shutdown timing of each service at runtime, persist that data somewhere, and once you have enough of it you can reduce the timeout for each service to a safe value, like the average clean exit + 6σ. It's never safe to pick "nice-looking" default numbers without knowing how long it actually takes in situ.


to post comments

Changing Fedora's shutdown timeouts

Posted Jan 19, 2023 0:35 UTC (Thu) by rahulsundaram (subscriber, #21946) [Link] (17 responses)

> This smells like premature optimization based on reading tea leaves and vibes, and a great way to make anyone running a large RDBMS side-eye any distro based on Fedora.

Don't see why. Things like PostgreSQL and libvirtd already override the default so there is no timeout for these services in Fedora.

Changing Fedora's shutdown timeouts

Posted Jan 19, 2023 9:56 UTC (Thu) by NYKevin (subscriber, #129325) [Link] (16 responses)

Those services really ought to be SIGKILLable at any time, or else ACID is a complete lie.

(For performance reasons, it is *preferable* to cleanly shut them down, so they do not have to reconcile their journals etc. on startup. But this is not, or should not be, a correctness problem, and imposing an arbitrary timeout might well be a completely reasonable tradeoff for a sysadmin to make. It's less clear to me whether the distro is in a good decision to provide a useful default.)

Changing Fedora's shutdown timeouts

Posted Jan 19, 2023 13:02 UTC (Thu) by kleptog (subscriber, #1183) [Link] (7 responses)

When I see this issue it's mainly caused by container-like constructions where the parent process in the "container" gains PID1 signal protections. Namely, a PID1 process may not be killed by a default signal handler. Since most processes don't install a signal handler for SIGKILL, such processes become immune to SIGKILL. Of course, many programs don't install a SIGTERM handler either, but that's somewhat more common.

This is the reason many container guides suggest using something like systemd, supervisord, dumb-init, tini, etc as the root process because those *do* install a SIGKILL handler which properly exits. The symptom is pretty clear: killing your container takes ages.

Of course, if SIGKILL fails, the entire cgroup gets nuked eventually, and there's no immunity from that.

Changing Fedora's shutdown timeouts

Posted Jan 27, 2023 11:19 UTC (Fri) by intelfx (subscriber, #130118) [Link] (6 responses)

> Since most processes don't install a signal handler for SIGKILL, such processes become immune to SIGKILL. Of course, many programs don't install a SIGTERM handler either, but that's somewhat more common.
>
> This is the reason many container guides suggest using something like systemd, supervisord, dumb-init, tini, etc as the root process because those *do* install a SIGKILL handler which properly exits. The symptom is pretty clear: killing your container takes ages.

There is something wrong. signal(7) says (in the Standard signals) that “the signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored”.

That’s the whole point of SIGKILL.

Changing Fedora's shutdown timeouts

Posted Jan 27, 2023 12:20 UTC (Fri) by Wol (subscriber, #4433) [Link]

Forgive me if I'm wrong, but - just as access rights do not apply to user 0 - signals do not apply to pid 1?

SIGKILL etc may be untrappable, but it's down to pid 1 to enforce that. Ergo, you cannot send pid 1 a SIGKILL and expect it to work.

Cheers,
Wol

Changing Fedora's shutdown timeouts

Posted Jan 28, 2023 3:38 UTC (Sat) by mathstuf (subscriber, #69389) [Link] (4 responses)

PID 1 only receives signals for which it installs handlers. It's a bit special in that way. When "random executable X" is launched directly in a container with a PID namespace, it becomes that namespace's PID 1 and since SIGKILL handlers are generally only done in programs *expecting* to be PID 1, these processes therefore become unkillable.

Changing Fedora's shutdown timeouts

Posted Jan 28, 2023 12:49 UTC (Sat) by izbyshev (subscriber, #107996) [Link] (3 responses)

There are no "SIGKILL handlers" (and SIGSTOP handlers). It's impossible to change signal disposition for SIGKILL and SIGSTOP[1], as intelfx pointed out, so no init process (whether global or from a pid namespace) can change the effects of these signals. They can't be sent to the global init because the kernel explicitly disallows that[2]. For pid namespace inits, SIGKILL and SIGSTOP are allowed if sent from an ancestor pid namespace[3].

[1] https://elixir.bootlin.com/linux/v6.1.8/source/kernel/sig...
[2] https://elixir.bootlin.com/linux/v6.1.8/source/kernel/sig...
[3] https://elixir.bootlin.com/linux/v6.1.8/source/kernel/sig...

Changing Fedora's shutdown timeouts

Posted Jan 28, 2023 16:30 UTC (Sat) by kleptog (subscriber, #1183) [Link] (2 responses)

Thanks. I'd just like to say I find the PID1 signal handling somewhat underdocumented. The clearest thing I could find was this LKML message[1] from 2008.

[1] https://lwn.net/Articles/312721/

So it's true that init processes cannot be killed by unhandled signals, and that usually what prevents containers inits from dying on SIGTERM. But that's not what protects them from SIGKILL, that's handled on the other end. What happens if a container init receives a SIGSEGV due to a memory fault but has no handler installed wasn't immediately clear to me (I think the force mechanism will cause it to die anyway, not sure).

Changing Fedora's shutdown timeouts

Posted Feb 5, 2023 19:45 UTC (Sun) by flussence (guest, #85566) [Link] (1 responses)

IIRC in a namespace, if PID1 is SIGKILLed (or just exits some other way), what happens is every *other* PID in there gets SIGKILLed.

And that's part of the contract which "Container-init must behave like global-init to processes within the container" from that link entails - when you kill PID1 on bare metal the system stops.

Changing Fedora's shutdown timeouts

Posted Feb 26, 2023 16:30 UTC (Sun) by nix (subscriber, #2304) [Link]

> And that's part of the contract which "Container-init must behave like global-init to processes within the container" from that link entails

This seems to conflict badly with the reality which has random programs running as PID 1 in single-service containers. Hardly any of these programs are expecting ever to suddenly become an init...

Changing Fedora's shutdown timeouts

Posted Jan 19, 2023 13:46 UTC (Thu) by dskoll (subscriber, #1630) [Link] (5 responses)

How can you implement something that keeps the ACID guarantee in the face of SIGKILL? I believe it's impossible.

Changing Fedora's shutdown timeouts

Posted Jan 19, 2023 13:48 UTC (Thu) by dskoll (subscriber, #1630) [Link] (1 responses)

Ugh, never mind. It has to be possible or else you couldn't have ACID guarantees in the case of sudden loss of power, I guess.

Changing Fedora's shutdown timeouts

Posted Jan 19, 2023 14:58 UTC (Thu) by madscientist (subscriber, #16861) [Link]

Yes. It's a matter of whether you want to spend time at shutdown, or time at startup. On the product I worked on we used to drain our journal at shutdown but customers hated that. They wanted the thing to go down when they told it to: draining the journal can take many minutes, sometimes, depending on the situation.

Since we have to support ACID / poweroff / kill -9 / etc. anyway, we changed our shutdown to basically call _exit() and now it's very fast :). But it does mean that when they next start the service it may take longer to start up because all that work of reconciling the journal has to be done then.

For people who are concerned about it there is a standalone tool that can be used to reconcile the journal in the background while the service is offline, rather than doing it at startup.

ACID guarantees in the face of SIGKILL

Posted Jan 19, 2023 14:10 UTC (Thu) by matthias (subscriber, #94967) [Link] (1 responses)

In the same way as journaling filesystem work. First write the transaction into a journal (usually called log for databases) and after the transaction is confirmed to be written, the actual database can be changed.

Usually you want to keep the log with all transactions even after they have been written to the database. Using the log, you can recreate the current database state from a backup. So your backup scheme is as follows: do a full backup once in a while and keep a backup of all log files since the last full backup.

ACID guarantees in the face of SIGKILL

Posted Jan 19, 2023 14:26 UTC (Thu) by Wol (subscriber, #4433) [Link]

And try (not always possible) to make sure the log is on different hardware, even if only a different disk ...

Cheers,
Wol

Changing Fedora's shutdown timeouts

Posted Jan 19, 2023 19:21 UTC (Thu) by kreijack (guest, #43513) [Link]

> How can you implement something that keeps the ACID guarantee in the face of SIGKILL? I believe it's impossible.

The ACID guarantee have to be keep even in case of a power failure.

I remember that in the past I read that because the software have to be secure against a power failure, we could switch off the kernel without worrying about a clean shutdown or sync/flush....

Changing Fedora's shutdown timeouts

Posted Jan 19, 2023 14:34 UTC (Thu) by MarcB (subscriber, #101804) [Link] (1 responses)

They are SIGKILLable, but this doesn't mean doing so is free. Usually you pay for it on the next start-up in the form of a potentially lengthy and IO intensive recovery.

Changing Fedora's shutdown timeouts

Posted Jan 20, 2023 4:40 UTC (Fri) by NYKevin (subscriber, #129325) [Link]

Yes, I wrote an entire parenthetical specifically addressing that.

Changing Fedora's shutdown timeouts

Posted Jan 19, 2023 6:51 UTC (Thu) by LtWorf (subscriber, #124958) [Link]

> This smells like premature optimization based on reading tea leaves and vibes

It seems it has never happened to you, while it has happened to me several times.

Good for you that your daemons aren't buggy and get stuck when stopped.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds