Drain background writers before process exit

Serialize writer submission and shutdown, enqueue explicit stop messages after accepted records, and finish the final file batch before joining. Keep drained process-wide channel storage until exit to avoid the Nim 2.2.10 Channel.close mutex teardown defect.

Cover empty records, multiple destinations, joined producers, and concurrent shutdown. Include writer lifecycle sanitizer tests in nimble test and update usage documentation.

Validation: all 32 unit tests, eight writer exit scenarios, and writer lifecycle ThreadSanitizer tests pass. The full suite retains the known configuration refresh, timestamp, and default allocator failures.
This commit is contained in:
jdb committed 2026-09-28 15:00:18 -05:00
1 parent b2d0e9dade
commit d5e3b9c301
7 files changed
+241 -125

No files matched your search

+5 -1
View File
@@ -34,10 +34,14 @@ proc runRegressionTests() =
proc runThreadSafetyTests() =
if fileExists("tests/bin/thread_safety"): rmFile("tests/bin/thread_safety")
if fileExists("tests/bin/writer_lifecycle"): rmFile("tests/bin/writer_lifecycle")
exec "nimble c --mm:orc --threads:on --passC:-fsanitize=thread --passC:-g --passL:-fsanitize=thread --out:tests/bin/thread_safety tests/thread_safety.nim"
if not fileExists("tests/bin/thread_safety"):
raise newException(OSError, "Thread-safety test compilation produced no executable")
exec "bash tests/run_tsan.sh tests/bin/thread_safety"
exec "nimble c --mm:orc --threads:on --passC:-fsanitize=thread --passC:-g --passL:-fsanitize=thread --out:tests/bin/writer_lifecycle src/namespaced_logging.nim"
if not fileExists("tests/bin/writer_lifecycle"):
raise newException(OSError, "Writer lifecycle test compilation produced no executable")
exec "bash tests/run_tsan.sh tests/bin/thread_safety tests/bin/writer_lifecycle"
task test, "Run all tests, including ThreadSanitizer, and report all failing suites.":
var failedSuites: seq[string] = @[]