Repository navigation
Fix LogMonitor normal-exit shutdown crash - #250
Merged
Merged
Conversation
Stop monitor workers before CRT teardown destroys the function-local formatter tables. Add real-process shutdown regressions for successful and nonzero child exits, with native and CMake test integration.
There was a problem hiding this comment.
🟡 Changes recommended
The remaining shutdown-test nit is that assertion failures omit captured output while cleanup deletes output.txt, obscuring missing events and error diagnostics in CI.
1 open issue
What changed in this PR
Fixes LogMonitor’s normal-exit shutdown crash by stopping ETW, file, and Event Log monitors before CRT teardown, preserving their destruction order and the child’s exit code.
Changes:
- Adds real-process regression tests for exit codes 0 and 37 with buffered ETW events.
- Integrates the tests into Visual Studio and CMake builds.
- Documents shutdown behavior and elevated, sequential test execution requirements.
| File | Description |
|---|---|
LogMonitor/src/LogMonitor/Main.cpp |
Stops monitors explicitly before returning. |
LogMonitor/README.md |
Documents shutdown behavior and test prerequisites. |
LogMonitor/LogMonitorTests/ShutdownTests.cpp |
Tests pending-event shutdown, exit codes, and resource cleanup. |
LogMonitor/LogMonitorTests/LogMonitorTests.vcxproj.filters |
Groups the new test source in Visual Studio. |
LogMonitor/LogMonitorTests/LogMonitorTests.vcxproj |
Includes the shutdown tests in the build. |
LogMonitor/LogMonitorTests/CMakeLists.txt |
Makes the test target depend on the production executable. |
Review effort: Max
Contributor
Author
|
/AzurePipelines run microsoft.windows-container-tools |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Contributor
Author
|
/AzurePipelines run microsoft.windows-container-tools |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Include captured output in missing-event and error assertions so cleanup does not erase the failure evidence. Explain why the suspended monitor must join its cleanup job before launching its child.
This was referenced Nov 13, 2026
Closed
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.

Summary
Fixes #245. Target release: v2.2.2.
Explicitly stop the ETW, file, and Event Log monitors before
wmainreturns, preserving their existing destruction order and the child process exit code.The crash occurred because CRT teardown destroyed function-local formatter tables before the global monitor destructors stopped their workers. Stopping the ETW session then delivered pending events to a worker that accessed those destroyed tables. This shutdown ordering was confirmed in the signed RC2 executable with matching symbols.
Regression coverage
LogMonitor.exeand verify child exit codes 0 and 37.Validation
The final regression fixture reproduces
0xC0000005in both cases against the unchanged signedv2.2.2-rc.2executable. Both cases pass with the fix, including three repetitions per build:The four-source runs cover ETW, EventLog, File, and Process output with child exit codes 0 and 37. All four sources produced records without error diagnostics. Native x64/x86 and CMake builds succeeded; cpplint 2.0.2 passed the changed C++ files, and the CRLF-aware whitespace check passed. These are focused checks, not a claim that the full suite was rerun for this change.
Review follow-up
Commit
f7529fbincludes captured output in both shutdown-event/error assertion messages and explains why the suspended monitor must be assigned to its cleanup job before starting. The production shutdown fix is unchanged.Native x64, native x86, and CMake x64 builds and both shutdown tests per build passed again. Two isolated negative controls verified that missing-event and reported-error failures retain real child/ETW output in their TRX messages after cleanup. Changed-file cpplint 2.0.2 and the CRLF-aware whitespace check also passed.
Release scope
This fix is intended for the v2.2.2 release train. The published RC2 tag and asset are unchanged. The separately tracked replay-shutdown issue #248 and embedded-NUL issue #249 are not claimed fixed by this PR.