Repository navigation
Register tracing log hook before signal handling - #13411
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Moves registration of the tracing logrus hook to immediately after config load/flag application, so the hook is in place before later startup steps spawn goroutines that may emit log entries.
Changes:
- Adds tracing hook registration right after
applyFlagsreturns, gated onconfig.Debug.LogTraceID. - Removes the previous, later hook registration that ran after signal/cleanup setup.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
moosepass
marked this pull request as ready for review
May 15, 2026 15:03
Member
|
/ok-to-test |
moosepass
force-pushed
the
moosepass/fix-tracing-hook-order
branch
2 times, most recently
from
May 15, 2026 15:19
271e92f to
cea539a
Compare
Signed-off-by: Abhishek Bhunia <[email protected]>
austinvazquez
force-pushed
the
moosepass/fix-tracing-hook-order
branch
from
June 2, 2026 20:40
cea539a to
125c15b
Compare
Contributor
|
LGTM |
samuelkarp
approved these changes
Jun 2, 2026
Kern--
approved these changes
Jun 2, 2026
austinvazquez
approved these changes
Jun 3, 2026
austinvazquez
left a comment
Member
There was a problem hiding this comment.
Throwing up my LGTM. I just rebased it to kick CI.
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Jun 3, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Jun 3, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Jun 4, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Jun 11, 2026
Member
|
I opened #13353 to resolve an underlying issue that prevented the last merge queue run (https://github.com/containerd/containerd/actions/runs/27363955475/job/80859027083) from succeeding. |
mxpv
approved these changes
Jun 25, 2026
This was referenced Sep 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Move tracing logrus hook registration earlier in daemon startup, immediately after config loading and CLI flags have been applied.
This avoids a startup ordering race where logrus hooks can be mutated after startup goroutines may already be logging.
Root Cause
This is not a logrus race that "shouldn't be possible". It is a real race that can happen when hook registration is delayed until after startup work begins.
The tracing hook used to be registered from
init(), before daemon startup spawned goroutines. That ordering was safe because the hook was installed before concurrent startup logging could begin.That changed when tracing hook registration moved into
cmd/containerd/command/main.go. The move was needed because the hook now depends onconfig.Debug.LogTraceID, which is only known after config loading and CLI flag application. So the hook can no longer be registered frominit().However, the current placement registers the hook after signal handling setup has started.
On Windows,
handleSignalscallssetupDumpStacks.setupDumpStacksstarts a goroutine whose first action is to log that it is waiting for the stackdump event:log.L.Debugf("Stackdump - waiting signal at %s", event).That creates this startup ordering:
Normally logrus serializes hook access with its logger mutex.
AddHooklocks while mutating hooks, and the logging path locks while copying hooks before firing them.However, users may run containerd with logrus locking disabled. One example is the
containerd/logslog bridge, whereUseSlog()callsSetNoLock(). Once locking is disabled, thoseLock/Unlockcalls become no-ops. At that point, logging can read/copy the hook map whileAddHookmutates it, which can panic with a concurrent map iteration/write.This is easiest to trigger on Windows because the stackdump goroutine logs immediately during signal handling setup. Unix signal handling does not start the same immediate stackdump logging goroutine, but the broader startup invariant still applies: hooks should be registered before startup goroutines that may log are started.
Fix
Register the tracing hook immediately after
applyFlags, which is the earliest point whereconfig.Debug.LogTraceIDis available.This preserves the
LogTraceIDconfigurability while restoring the previous ordering property: known hooks are registered before later startup steps may spawn goroutines that log.The change is intentionally small: it only moves the existing tracing hook registration earlier in startup and documents why the placement matters.
Testing
go test ./cmd/containerd/command/... -count=1go test ./cmd/containerd/... -count=1