Skip to content

core/service: reload fixlets - #39376

Merged
yuwata merged 21 commits into
systemd:mainfrom
YHNdnzj:reload-refresh-revamp
Nov 4, 2025
Merged

yuwata merged 21 commits into
systemd:mainfrom
YHNdnzj:reload-refresh-revamp

Conversation

@YHNdnzj

@YHNdnzj YHNdnzj commented Oct 20, 2025 •

Copy link
Copy Markdown
Member

Fixes #37515

@YHNdnzj YHNdnzj added the pid1 label Oct 20, 2025
@YHNdnzj YHNdnzj added this to the v259 milestone Oct 20, 2025
@YHNdnzj
YHNdnzj requested a review from poettering October 20, 2025 00:05
@YHNdnzj
YHNdnzj force-pushed the reload-refresh-revamp branch 2 times, most recently from 838b2ee to 074cbac Compare October 20, 2025 01:05
@YHNdnzj YHNdnzj added the please-review PR is ready for (re-)review by a maintainer label Oct 20, 2025
@YHNdnzj
YHNdnzj force-pushed the reload-refresh-revamp branch from 074cbac to c7c7e57 Compare October 20, 2025 21:08
@YHNdnzj
YHNdnzj marked this pull request as ready for review October 20, 2025 21:14
@YHNdnzj
YHNdnzj force-pushed the reload-refresh-revamp branch from c7c7e57 to 9ef3ca5 Compare October 20, 2025 21:31
@YHNdnzj

YHNdnzj commented Oct 20, 2025

Copy link
Copy Markdown
Member Author

Updated the man page now. Should be complete. PTAL!

@yuwata yuwata left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you add test cases for the original issue and the new feature?

Comment thread src/core/service.c Resolved
Comment on lines +2859 to +2860
readonly a(sasbttttuii) ExecReloadPost = [...];
@org.freedesktop.DBus.Property.EmitsChangedSignal("invalidates")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's questionable we should introduce ExecRelaodPost (non-Ex version)...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, annoyed me for a while too. But our internal logic determines the type based on whether the property ends with "Ex", and it creates more churn to restructure all that...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hmm, but why not keep just the Ex version, and kill the non-Ex version?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Will update like that

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Actually we can't - bus_append_exec_command tries to patch Ex back to non-Ex properties if no new exec flags are used :/

@YHNdnzj

YHNdnzj commented Oct 21, 2025 •

Copy link
Copy Markdown
Member Author

Could you add test cases for the original issue and the new feature?

I'll just add tests for the issue for now. I'd like @poettering 's blessing before doing tedious work for ExecReloadPost=

@YHNdnzj
YHNdnzj force-pushed the reload-refresh-revamp branch from 9ef3ca5 to 3d713d0 Compare October 21, 2025 23:53
@github-actions github-actions Bot added the tests label Oct 21, 2025
@YHNdnzj
YHNdnzj force-pushed the reload-refresh-revamp branch 4 times, most recently from 52c0bbb to 9e96073 Compare October 22, 2025 19:11
Comment thread man/systemd.service.xml Resolved
Comment thread src/core/service.c
/* If notify state is still in dangling NOTIFY_RELOADING, reset it so service_enter_running()
* won't get confused (see #37515) */
if (s->notify_state == NOTIFY_RELOADING)
s->notify_state = _NOTIFY_STATE_INVALID;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i wonder if this is racy? i.e. let's say an ExecReload= cmd fails with an unclean exit code, and we now end up here, but in the time the cmd failed and we come here the user already tried to reload the service another way, so we get another RELOADING=1 here. We'll now ignore htat, and miss the state change.

we could probably make this airtight, by only resetting things here if the timestamp of the msg predate the actual state change to reloading state?

or am i overthinking this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

My conclusion so far is that ExecReload= is inherently racy. We simply don't know if the RELOADING=1 the main process sent us is due to ExecReload= doing its thing or from extrinsic event. It could be sent before executor handoff - sure we have handoff timestamps now but that's just part of the problem.

To main goal of this patchset is to make sure ExecReload= and ReloadSignal= work together consistently. Previously some states in between are ill-formed, now ExecReload= can be used for e.g. pre-reload businesses (config check?) as well as signaling the actual reload. If it's the former, the notify-reload protocol fires which is not racy; for the latter it's all about creativity ;)

@poettering

Copy link
Copy Markdown
Member

i am not totally against the ExecReloadPost= stuff, but would like to hear some usecase.

Looks great otherwise.

@poettering poettering 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 Oct 28, 2025
@YHNdnzj

YHNdnzj commented Oct 28, 2025

Copy link
Copy Markdown
Member Author

Hmm, the idea is that previously ExecReload= is invoked in parallel with ReloadSignal=, so the custom reload command can in theory do post-reload tasks. That would be invalidated if ExecReload= is brought upfront. I don't have any concrete examples in mind. Happy to drop the addition of ExecReloadPost=. I was just trying to make the impact of last commit more visible.

@YHNdnzj YHNdnzj added the please-review PR is ready for (re-)review by a maintainer label Oct 28, 2025
@YHNdnzj YHNdnzj removed the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Oct 30, 2025
@YHNdnzj
YHNdnzj force-pushed the reload-refresh-revamp branch from 9e96073 to e411d43 Compare October 30, 2025 23:39
@poettering poettering added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed and removed please-review PR is ready for (re-)review by a maintainer labels Nov 4, 2025
They don't take pointers, hence are eligible for stronger guarantees.
The impl is directly visible to the compiler so it can apply
all sorts of optimizations wherever it sees fit. And with
the previous commit they are actually "const".
reload_begin_usec is a barrier for determining whether RELOADING=1
came after the main process got signaled, unrelated to refreshing.
{service,socket}_unwatch_control_pid() -> unit_unwatch_pidref_done()
is unconditionally called everywhere.
If we're changing state anyways, service_set_state() -> unit_notify()
will take care of dbus signaling for us.
We usually use _INVALID enum value as placeholder.

While at it, reset notify_state in service_enter_dead() for consistency.
This really should be persisted across daemon-reload since
it might contain deferred state transitions.
No functional change, preparation for later changes.
We don't permit state transition from STOPPING back to RUNNING,
hence refrain from resetting notify_state too.
…d ExecReloadPost=

When Type=notify-reload got introduced, it wasn't intended to be
mutually exclusive with ExecReload=. However, currently ExecReload=
is immediately forked off after the service main process is signaled,
leaving states in between essentially undefined. Given so broken
it is I doubt any sane user is using this setup, hence I took a stab
to rework everything:

1.  Extensions are refreshed (unchanged)
2.  ExecReload= is forked off without signaling the process
3a. If RELOADING=1 is sent during the ExecReload= invocation,
    we'd refrain from signaling the process again, instead
    just transition to SERVICE_RELOAD_NOTIFY directly and
    wait for READY=1
3b. If not, signal the process after ExecReload= finishes
    (from now on the same as Type=notify-reload w/o ExecReload=)
4.  To accomodate the use case of performing post-reload tasks,
    ExecReloadPost= is introduced which executes after READY=1

The new model greatly simplifies things, as no control processes
will be around in SERVICE_RELOAD_SIGNAL and SERVICE_RELOAD_NOTIFY
states.

See also: systemd#37515 (comment)
@YHNdnzj
YHNdnzj force-pushed the reload-refresh-revamp branch from e411d43 to ca86581 Compare November 4, 2025 11:22
@yuwata
yuwata merged commit 71d64f0 into systemd:main Nov 4, 2025
@github-actions github-actions Bot removed the good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed label Nov 4, 2025
@YHNdnzj
YHNdnzj deleted the reload-refresh-revamp branch November 4, 2025 18:17
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.

Type=notify-reload units that don't send READY=1 after RELOADING=1 stay stuck reloading instead of timing out after TimeoutStartSec= seconds

3 participants