Skip to content

fix(googlecloudcommon): cancel context on receiver exit to prevent deadlock in TestLogFetcherImpl_FetchLogs - #1004

Merged
kyasbal merged 1 commit into
GoogleCloudPlatform:mainfrom
kyasbal:push-lkwwzlqyyxzt
Sep 15, 2026
Merged

kyasbal merged 1 commit into
GoogleCloudPlatform:mainfrom
kyasbal:push-lkwwzlqyyxzt

Conversation

@kyasbal

@kyasbal kyasbal commented Sep 15, 2026

Copy link
Copy Markdown
Member

Summary

In pkg/task/inspection/googlecloudcommon/contract/logfetcher_test.go, TestLogFetcherImpl_FetchLogs could 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

  1. In TestLogFetcherImpl_FetchLogs, the receiver goroutine receives a log from destChan (an unbuffered channel) or times out via case <-time.After(20 * time.Second):.
  2. When the 20-second timeout fired, 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:).
  3. As a result, when the receiver exited on timeout, ctx remained active. When fetcher.FetchLogs subsequently fetched a log entry, it attempted to send to destChan (select { case dest <- entry: case <-ctx.Done(): }). Since no receiver existed and ctx was not cancelled, fetcher.FetchLogs blocked indefinitely until the parent test timeout (10 minutes) was reached.

Fix

Added defer cancel() at the start of the receiver goroutine, ensuring cancel() is always invoked when the goroutine exits (on normal receive, timeout, or channel closure). This ensures that <-ctx.Done() unblocks fetcher.FetchLogs, allowing it to terminate promptly and return context.Canceled.

Verification

  • go test -v ./pkg/task/inspection/googlecloudcommon/contract -run TestLogFetcherImpl_FetchLogs passed cleanly.
  • make test-go passed across all backend packages.
  • make lint-go and make pre-commit passed with 0 issues.
@kyasbal kyasbal added type:bug Something isn't working as expected area:backend-parser Log parsers and log timeline mapper tasks labels Sep 15, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kyasbal
kyasbal added this pull request to the merge queue Sep 15, 2026
Merged via the queue into GoogleCloudPlatform:main with commit f64b44f Sep 15, 2026
17 checks passed
@kyasbal
kyasbal deleted the push-lkwwzlqyyxzt branch September 15, 2026 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend-parser Log parsers and log timeline mapper tasks type:bug Something isn't working as expected

1 participant