Skip to content
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

journal: explicitly sync namespaced journals before stopping socket uunits #32619

Merged
merged 1 commit into from
May 2, 2024

Conversation

yuwata
Copy link
Member

@yuwata yuwata commented May 1, 2024

Otherwise, if a service unit that requests LogNamespace= stopped before systemd-journald@.service is started, logs generated by the service will be lost, as systemd-journald@.socket is stopped and
systemd-journald@.service will never started.

To prevent the issue, let's introduce another implicit dependency to a oneshot service that explicitly synchronizes a namespaced journal file when the log namespace is not needed anymore.

Fixes #32604.

@github-actions github-actions bot added build-system meson please-review PR is ready for (re-)review by a maintainer labels May 1, 2024
Copy link

github-actions bot commented May 1, 2024

Important

An -rc1 tag has been created and a release is being prepared, so please note that PRs introducing new features and APIs will be held back until the new version has been released.

…nits

Otherwise, if a service unit that requests LogNamespace= stopped before
systemd-journald@.service is started, logs generated by the service will be
lost, as systemd-journald@.socket is stopped and
systemd-journald@.service will never started.

To prevent the issue, let's introduce another implicit dependency to
a oneshot service that explicitly synchronizes a namespaced journal file
when the log namespace is not needed anymore.

Fixes systemd#32604.
Comment on lines +1316 to +1332
r = unit_name_build_from_type("systemd-journald", c->log_namespace, UNIT_SOCKET, &unit);
if (r < 0)
return r;

r = unit_add_two_dependencies_by_name(u, UNIT_AFTER, UNIT_REQUIRES, socket_unit, true, UNIT_DEPENDENCY_FILE);
r = unit_add_two_dependencies_by_name(u, UNIT_AFTER, UNIT_REQUIRES, unit, true, UNIT_DEPENDENCY_FILE);
if (r < 0)
return r;

r = unit_name_build_from_type("systemd-journald-varlink", c->log_namespace, UNIT_SOCKET, &varlink_socket_unit);
unit = mfree(unit);

r = unit_name_build_from_type("systemd-journald-varlink", c->log_namespace, UNIT_SOCKET, &unit);
if (r < 0)
return r;

r = unit_add_two_dependencies_by_name(u, UNIT_AFTER, UNIT_REQUIRES, unit, true, UNIT_DEPENDENCY_FILE);
if (r < 0)
return r;
Copy link
Member

Choose a reason for hiding this comment

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

FOREACH_STRING can be used for these two

Copy link
Member

Choose a reason for hiding this comment

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

this fixes tests so let's get it merged and fixup later if needed

@richardmaw-codethink
Copy link
Contributor

This approach seems to fix it for me.

It took 5 tries of running TEST-44-LOG-NAMESPACE under heavy load for the bug to happen before cherry-picking this commit, and then it ran for an hour without problems afterwards so I'm fairly confident this works.

@bluca bluca merged commit 6162828 into systemd:main May 2, 2024
42 of 49 checks passed
@github-actions github-actions bot removed the please-review PR is ready for (re-)review by a maintainer label May 2, 2024
@yuwata yuwata deleted the journal-namespace-sync branch May 3, 2024 03:34
g7 pushed a commit to droidian/systemd that referenced this pull request May 14, 2024
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.

Log output can be lost from services using log namespaces that only produce output immediately before exiting
4 participants