Skip to content

fix(logging): harden async logger shutdown - #100

Merged
LimiNode merged 5 commits into
mainfrom
fix/async-logger-shutdown-lifecycle
May 19, 2026
Merged

fix(logging): harden async logger shutdown#100
LimiNode merged 5 commits into
mainfrom
fix/async-logger-shutdown-lifecycle

Conversation

@LimiNode

@LimiNode LimiNode commented May 19, 2026

Copy link
Copy Markdown
Owner

Summary

  • stop logger-owned async workers through shutdown() and reject direct backend logs after shutdown
  • close Logger::shutdown() races for add/dispatch and harden MPSC hot resize against active producers
  • fix MPSC TaskExecutor::wait() so it cannot return between dequeue cell release and task execution
  • serialize OTLP sync exports with shutdown and keep async Block producers wakeable during stop
  • clean OTLP include policy and update TaskExecutor lifecycle documentation
  • add regression tests for backend terminal shutdown, Logger shutdown races, TaskExecutor resize races, and Emscripten SingleThreadExecutor policies

Test Plan

  • git diff --check -- . ':!external/zlib'
  • g++ -std=c++17 -Iinclude/logit_cpp -Iexternal/time-shield-cpp/include tests/raw_file_logger_test.cpp -o tmp/codex_verify/raw_file_logger_test.exe + run
  • g++ -std=c++11 -Iinclude/logit_cpp -Iexternal/time-shield-cpp/include tests/backend_shutdown_terminal_test.cpp -o tmp/codex_verify/backend_shutdown_terminal_test.exe + run
  • g++ -std=c++11 -Iinclude/logit_cpp -Iexternal/time-shield-cpp/include tests/logger_shutdown_race_test.cpp -o tmp/codex_verify/logger_shutdown_race_test.exe + run
  • g++ -std=c++11 -Iinclude/logit_cpp -Iexternal/time-shield-cpp/include tests/task_executor_resize_race_test.cpp -o tmp/codex_verify/task_executor_resize_race_test.exe + run
  • OTLP header compile probe via <logit.hpp> with a temporary local mock kurlyk.hpp, then run
  • earlier: cmake -S . -B build-codex -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug
  • earlier: cmake --build build-codex -j 4 (blocked only by unrelated untracked tests/test_mdc_ndc.cpp, which references MDC/NDC macros absent from this branch)
  • earlier: ctest --test-dir build-codex --output-on-failure -E test_mdc_ndc

Notes

  • Emscripten-specific tests were expanded but not run locally because emcmake / em++ were unavailable on this machine.
  • Full local CMake regeneration is still affected by unrelated local artifacts/configuration: untracked tests/test_mdc_ndc.cpp is picked up by the test glob, and the existing build-mingw directory fails regeneration on a zlib export-set issue.

LimiNode added 5 commits May 19, 2026 01:40
Make the per_logger_mixed_mode_test probe logger call shutdown from its destructor so tasks submitted to the global TaskExecutor cannot run after the stack logger is destroyed.

This mirrors the built-in async logger lifecycle and fixes the macOS post-main crash where the test printed all PASS lines but CTest still observed a failed process exit.
Stop logger-owned workers during shutdown, prevent Logger dispatch after shutdown races, and guard direct backend log calls once a backend is closed.

Add regression coverage for backend terminal shutdown, Logger shutdown races, TaskExecutor hot-resize producers, and Emscripten SingleThreadExecutor policies.
Serialize OTLP sync exports with shutdown while letting async blocked producers release the lifecycle lock so stop can wake them. Use explicit acquire-release ordering for Logger shutdown and make TaskExecutor queue policy updates a no-op after shutdown, matching resize lifecycle semantics.
Mark the MPSC worker active before popping from the ring so TaskExecutor::wait() cannot observe an empty queue between cell release and task execution. This closes a TSAN-visible early-return window that let raw_file_logger_test read before the async write completed.
Update the TaskExecutor lifecycle mutex comment to reflect that it now serializes shutdown with all lifecycle-changing operations, including queue policy updates.
@LimiNode
LimiNode merged commit e9f237d into main May 19, 2026
12 checks passed
@LimiNode
LimiNode deleted the fix/async-logger-shutdown-lifecycle branch May 21, 2026 19:52
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.

1 participant