Repository navigation
test(kernel): stop leaked drain-test goroutines writing into TestLogSinkForwardMapsLevels' log buffer - #559
Merged
Merged
Conversation
TestDrainRecoversFromWriterPanic and TestDrainContainsPanicFromForwardAndDropWarning
started drainKernelLogs without waiting for it to exit. observe signals the test
before forward writes the record, so the drain's final write could land after the
test returned, in the buffer TestLogSinkForwardMapsLevels had just installed
(CI: "invalid character '{' after top-level value"; the stray record was the
drain test's {"message":"after"}).
A startDrain helper now closes the channel and waits for the drain at cleanup,
before the earlier-registered cleanup restores the shared output.
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
vuanhphung
marked this pull request as ready for review
November 13, 2026 18:53
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.
TestLogSinkForwardMapsLevelsfails intermittently in CI withinvalid character '{' after top-level value(seen in the kernel-backend lane on #557). The test points the shared driver logger at a buffer and expects exactly one JSON record. A second record lands in that buffer:{"level":"info","target":"databricks::sql::kernel","message":"after"}. The previous test,TestDrainContainsPanicFromForwardAndDropWarning, enqueues that record.The two drain tests started
drainKernelLogswithgo ...; defer close(ch)and never waited for the goroutine to exit. Theirobservehook signals the test beforeforwardwrites the record. The drain's last write can therefore happen after the test returns, by which time the next test has retargeted the shared output to its own buffer. The race detector reports the same thing as a data race on thatbytes.Buffer, with the writer created atlogforward_async_test.go:127(and:78forTestDrainRecoversFromWriterPanic). This is test isolation, not a production leak: production starts the drain once per process by design, because the kernel's tracing subscriber is process-wide and first-call-wins.The fix is a
startDraintest helper. At cleanup it closes the channel and waits (bounded at 5s) for the drain to return. That cleanup runs before the earlier-registered cleanup restores the shared output, and in the queue test the queue is unpublished before the channel is closed. No production code and no assertions change.TestLogSinkFollowsLocalFileRetargetandTestKernelLogCtxEmitsCorrelationalso swap the logger, but neither starts a goroutine. They were only victims of the leaked drains, so they're unchanged.Verification. Prebuilt test binaries, 32 instances pinned to 2 CPUs to mimic a contended runner,
-run 'TestDrain|TestLogSink', main and branch alternated:databricks_kernel(CI lane config)-race-raceOn an idle machine main passes 0/500, which is why this only shows up in CI. A scratch test that widens the observe→write window deterministically fails with the old pattern and passes with
startDrain. On the branch with-race, these are clean:-count=500ofTestLogSinkand ofTestDrain|TestLogSink(tagged and untagged), and-count=50of the whole package (tagged and untagged).make testandmake lintpass. The change is test-only, so there's no performance or e2e effect.Cross-driver state: Not applicable (Go-internal test hygiene).
Adversarial review: converged in round 1 with no findings.
No issue filed; seen on #557's CI.
This pull request and its description were written by Isaac.