Repository navigation
fix(googlecloudcommon): cancel context on receiver exit to prevent deadlock in TestLogFetcherImpl_FetchLogs - #1004
Merged
Conversation
…adlock in TestLogFetcherImpl_FetchLogs
kyasbal
requested review from
K53,
RyuSA,
jyane,
kkuchima and
renamoo
as code owners
September 15, 2026 07:26
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the TestLogFetcherImpl_FetchLogs test in logfetcher_test.go to defer the cancel() call of the context within the goroutine, ensuring it is always executed when the goroutine exits. The manual cancel() call inside the select block has been removed. There are no review comments, and I have no feedback to provide.
Merged
via the queue into
GoogleCloudPlatform:main
with commit Sep 15, 2026
f64b44f
17 checks passed
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
In
pkg/task/inspection/googlecloudcommon/contract/logfetcher_test.go,TestLogFetcherImpl_FetchLogscould intermittently deadlock and hit the 10-minute test runner timeout if Cloud Logging does not return a log within the 20-second threshold.Problem & Root Cause
TestLogFetcherImpl_FetchLogs, the receiver goroutine receives a log fromdestChan(an unbuffered channel) or times out viacase <-time.After(20 * time.Second):.t.Errorf("no logs returned for the first 20 sec")was emitted and the receiver goroutine terminated. However,cancel()was only invoked in the successful receive branch (case _, ok := <-destChan:).ctxremained active. Whenfetcher.FetchLogssubsequently fetched a log entry, it attempted to send todestChan(select { case dest <- entry: case <-ctx.Done(): }). Since no receiver existed andctxwas not cancelled,fetcher.FetchLogsblocked indefinitely until the parent test timeout (10 minutes) was reached.Fix
Added
defer cancel()at the start of the receiver goroutine, ensuringcancel()is always invoked when the goroutine exits (on normal receive, timeout, or channel closure). This ensures that<-ctx.Done()unblocksfetcher.FetchLogs, allowing it to terminate promptly and returncontext.Canceled.Verification
go test -v ./pkg/task/inspection/googlecloudcommon/contract -run TestLogFetcherImpl_FetchLogspassed cleanly.make test-gopassed across all backend packages.make lint-goandmake pre-commitpassed with 0 issues.