Skip to content

Fix LogMonitor normal-exit shutdown crash - #250

Merged
bob sira (bobsira) merged 2 commits into
mainfrom
fix/logmonitor-normal-exit-shutdown
Nov 13, 2026
Merged

bob sira (bobsira) merged 2 commits into
mainfrom
fix/logmonitor-normal-exit-shutdown

Conversation

@bobsira

@bobsira bob sira (bobsira) commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #245. Target release: v2.2.2.

Explicitly stop the ETW, file, and Event Log monitors before wmain returns, 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

  • Add real-process tests that launch the adjacent production LogMonitor.exe and verify child exit codes 0 and 37.
  • Observe an ETW warm-up event to initialize formatter tables, then extend the flush timer and queue an event for session-stop delivery.
  • Require the queued event to be emitted, no LogMonitor error diagnostics, and no remaining ETW session. Use a private job object for process cleanup.
  • Include the tests in the Visual Studio project and make the CMake test target depend on the production executable; document elevated, sequential execution prerequisites.

Validation

The final regression fixture reproduces 0xC0000005 in both cases against the unchanged signed v2.2.2-rc.2 executable. Both cases pass with the fix, including three repetitions per build:

Build Repeated shutdown tests Four-source normal-exit runs
Native x64 Release 6/6 passed 2/2 passed
Native x86 Release 6/6 passed 2/2 passed
CMake x64 Release 6/6 passed 2/2 passed

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 f7529fb includes 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.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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

@bobsira

Copy link
Copy Markdown
Contributor Author

/AzurePipelines run microsoft.windows-container-tools

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@bobsira

Copy link
Copy Markdown
Contributor Author

/AzurePipelines run microsoft.windows-container-tools

@azure-pipelines

Copy link
Copy Markdown
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] LogMonitor crashes with 0xC0000005 on shutdown after normal child exit

3 participants