fix(logging): harden async logger shutdown - #100
Merged
Conversation
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.
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
shutdown()and reject direct backend logs after shutdownLogger::shutdown()races for add/dispatch and harden MPSC hot resize against active producersTaskExecutor::wait()so it cannot return between dequeue cell release and task executionBlockproducers wakeable during stopTest 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+ rung++ -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+ rung++ -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+ rung++ -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<logit.hpp>with a temporary local mockkurlyk.hpp, then runcmake -S . -B build-codex -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debugcmake --build build-codex -j 4(blocked only by unrelated untrackedtests/test_mdc_ndc.cpp, which references MDC/NDC macros absent from this branch)ctest --test-dir build-codex --output-on-failure -E test_mdc_ndcNotes
emcmake/em++were unavailable on this machine.tests/test_mdc_ndc.cppis picked up by the test glob, and the existingbuild-mingwdirectory fails regeneration on a zlib export-set issue.