Repository navigation
fix(inspection/googlecloudcommon): avoid race condition dropping partition boundary logs in log fetcher - #947
Merged
Conversation
… fetcher In StandardProgressReportableLogFetcher.FetchLogsWithProgress, when FetchLogs returned, subroutineCtx was cancelled while dest <- logEntry could still be pending in the consumer goroutine. Go select would randomly pick <-subroutineCtx.Done(), causing the final log entry of a time partition to be dropped intermittently. This change: - Separates consumer and progress synchronization contexts so that successful log fetching drains stubChan completely before progress reporting stops. - Sorts node names in NodeNameInventoryTask to guarantee deterministic query partitioning order. - Allows null values in SetFormTask to gracefully fall back to default values instead of erroring on array cast.
kyasbal
requested review from
K53,
RyuSA,
jyane,
kkuchima and
renamoo
as code owners
September 3, 2026 02:36
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a nil check for form task values, sorts node names in the node name inventory task, and refactors context and wait group management in FetchLogsWithProgress to separate consumer and progress reporting lifecycles. Feedback is provided to ensure that context cancellation errors are correctly propagated if the context is cancelled during the log draining phase.
…or during log draining
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
This PR resolves an intermittent issue where logs at time partition boundaries were randomly dropped during log fetching, causing non-deterministic log counts across inspection runs.
Root Cause
In
StandardProgressReportableLogFetcher.FetchLogsWithProgress, a consumer goroutine forwards log entries fromstubChantodest. WhenFetchLogsreturned synchronously,cancelSubroutine()immediately cancelledsubroutineCtx.Because the consumer goroutine used:
If
cancelSubroutine()executed while forwarding a log entry, Go'sselectstatement would randomly pick between the cancelled context anddest <- logEntry. When<-subroutineCtx.Done()won the race (~50% chance), the final log entry of that time partition was discarded.Fix Details
stubChanbefore stopping progress reporting (progressreportablelogfetcher.go):consumerCtx,progressCtx,consumerWg,progressWg).FetchLogscompletes,consumerWg.Wait()waits for the consumer goroutine to fully drainstubChanuntil closed (!ok) without cancellingconsumerCtx.nodenameinventory_task.go):slices.Sort(ret)tonodeNameMergeStrategy.Mergeto ensure node query split orders are strictly deterministic across runs.nullParameter Handling (setform.go):valueRaw == nilinSetFormTaskso passingnullin job inspection values falls back to the default empty array instead of failing withrequest parameter ... was not given in array.Verification
autoscaler,compute-api,gke-api,k8s-container,k8s-control-plane,k8s-event,k8s-node,network-api,serialport,k8s-auditlog).make lint-goandmake test-gopassed with 0 issues.