Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

core/socket: introduce DeferTrigger= #37505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
Loading
from

Conversation

YHNdnzj
Copy link
Member

@YHNdnzj YHNdnzj commented May 17, 2025

Follow-up for #37222 and #37421

@YHNdnzj YHNdnzj added the pid1 label May 17, 2025
@YHNdnzj YHNdnzj force-pushed the socket-defer-activation branch 2 times, most recently from 9f2768d to b34a35f Compare May 17, 2025 13:31
@YHNdnzj YHNdnzj force-pushed the socket-defer-activation branch 7 times, most recently from d17b37f to c34b424 Compare May 17, 2025 14:29
@septatrix
Copy link
Contributor

Would there be any gain in generalizing this such that it could also be used for timer or path units?

Copy link
Member

@yuwata yuwata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Looks basically good. Several comments.

Please add test cases for the setting.

src/core/manager.c Outdated Show resolved Hide resolved
src/core/manager.c Outdated Show resolved Hide resolved
src/core/socket.c Outdated Show resolved Hide resolved
src/core/socket.c Outdated Show resolved Hide resolved
src/core/unit.c Outdated Show resolved Hide resolved
units/systemd-udevd-kernel.socket Show resolved Hide resolved
man/systemd.socket.xml Show resolved Hide resolved
@YHNdnzj YHNdnzj added this to the v258 milestone May 17, 2025
@YHNdnzj
Copy link
Member Author

YHNdnzj commented May 17, 2025

Would there be any gain in generalizing this such that it could also be used for timer or path units?

So, hmm, I'm certainly not against future extensions like this. But OTOH no actual interest has been observed there. The reason why this is strictly necessary for sockets is that they get continuously woken up due to unprocessed IO, which is not a concern for timers/inotify. I can see how this may benefit, however not feeling like adding those immediately.

@YHNdnzj YHNdnzj force-pushed the socket-defer-activation branch 3 times, most recently from 5b779d3 to a50b08f Compare May 18, 2025 02:02
@github-actions github-actions bot added the tests label May 18, 2025
@YHNdnzj YHNdnzj force-pushed the socket-defer-activation branch 3 times, most recently from 1f1b8fa to c590446 Compare May 18, 2025 18:47
@YHNdnzj YHNdnzj force-pushed the socket-defer-activation branch from c590446 to 9069f66 Compare May 18, 2025 19:16
@YHNdnzj YHNdnzj marked this pull request as ready for review May 18, 2025 19:42
@github-actions github-actions bot added the please-review PR is ready for (re-)review by a maintainer label May 18, 2025
@YHNdnzj YHNdnzj force-pushed the socket-defer-activation branch from 9069f66 to ba38ac7 Compare May 19, 2025 16:24
@@ -338,6 +338,7 @@ DEFINE_STRING_TABLE_LOOKUP(notify_access, NotifyAccess);

static const char* const job_mode_table[_JOB_MODE_MAX] = {
[JOB_FAIL] = "fail",
[JOB_MEEK] = "meek",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe call this "additive"? or "augment"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. I think "additive" kinda misses the part that this bails on conflict?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"tentative" ?

src/core/socket.c Show resolved Hide resolved
src/core/socket.c Show resolved Hide resolved
man/systemd.socket.xml Outdated Show resolved Hide resolved
man/systemd.socket.xml Outdated Show resolved Hide resolved
@YHNdnzj YHNdnzj added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks and removed please-review PR is ready for (re-)review by a maintainer labels May 21, 2025
@YHNdnzj YHNdnzj force-pushed the socket-defer-activation branch from ba38ac7 to ba84305 Compare May 22, 2025 12:38
@github-actions github-actions bot added please-review PR is ready for (re-)review by a maintainer and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels May 22, 2025
@YHNdnzj YHNdnzj force-pushed the socket-defer-activation branch 3 times, most recently from eb88d44 to 291e494 Compare May 22, 2025 12:48
@YHNdnzj
Copy link
Member Author

YHNdnzj commented May 22, 2025

Introduced DeferTriggerMaxSec= as requested, PTAL

@YHNdnzj YHNdnzj force-pushed the socket-defer-activation branch from 291e494 to 6256433 Compare May 22, 2025 19:35
won't be disturbed/brought down. Furthermore, if a conflict exists, the socket unit will wait for
current job queue to complete and potentially defer the activation by then. An upper limit of
total time to wait can be configured via <varname>DeferTriggerMaxSec=</varname>. The socket unit
will fail if all jobs have finished or the timeout has been reached but the conflict remains.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition if all jobs have finished should be dropped, and always wait for the max sec.

src/core/manager.h Outdated Show resolved Hide resolved
return true; /* changed */
}
if (sd_bus_error_has_name(&error, BUS_ERROR_TRANSACTION_IS_DESTRUCTIVE)) {
if (!hashmap_isempty(u->manager->jobs))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now max delay is implemented, then the condition should not be necessary anymore.

if (s->defer_trigger) {
r = manager_add_job(UNIT(s)->manager, JOB_START, UNIT_DEREF(s->service), JOB_MEEK, &error, /* ret = */ NULL);
if (r < 0 && sd_bus_error_has_name(&error, BUS_ERROR_TRANSACTION_IS_DESTRUCTIVE) &&
!hashmap_isempty(UNIT(s)->manager->jobs))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here also.

@YHNdnzj
Copy link
Member Author

YHNdnzj commented May 23, 2025

I really don't understand the back and forth with the job pool being empty part. Should it get dropped, timer would become the "canonical" source of defer, which completely misses the point that the conflicting dependency is what actually matters here, not the time as an extra (optional) safety net.

In the specific use case of switch-root/soft-reboot it matters as mentioned, because you can't possibly know how long it would take for the stop phase to complete. Trying to set up a timer as boundary is futile. OTOH it makes perfect sense to bail if there're no jobs, from which point on we just can't expect the conflict to resolve itself anymore.

That's precisely why DelayTriggerMaxSec= defaults to infinity btw. It is optional and non-bearing in the job engine. Some people might wish that the socket gets terminated eventually on a busy system, but otherwise the activation falls on jobs, not the timer.

YHNdnzj added 7 commits May 23, 2025 18:39
Follow-up for 02229df

This applies the change to journal namespace instances too.
Alternative to b50f6db
This partially reverts d766c75

The commit naively returned early from socket_enter_running(), which however
is quite problematic, as the socket will be woken up over and over again
without doing a thing, until we eventually hit Poll/TriggerLimit*=.
On top of that it requires hacks to hold the start job for initrd-switch-root.service
up. Overall I doubt that is the right approach.

Let's instead hook this into our job engine, and try to activate
the service again when some other units are stopped. If all installed
jobs have been run yet we're still seeing the conflict or the manually
selected timeout is reached, fail the socket as before.
systemd-journald.service conflicts with soft-reboot.target,
so make sure anything surviving soft-reboot and trying
to log to journal doesn't fail the socket units.
@YHNdnzj
Copy link
Member Author

YHNdnzj commented May 23, 2025

IOW, this is called DeferTriggerMaxSec= instead of DeferTriggerSec= for a reason...

@YHNdnzj YHNdnzj force-pushed the socket-defer-activation branch from 6256433 to ee389d5 Compare May 23, 2025 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.