fix: tolerate stderr-polluted moduleGraphJson in ModuleGraphParser#336
Open
rdark wants to merge 1 commit intoTinder:masterfrom
Open
fix: tolerate stderr-polluted moduleGraphJson in ModuleGraphParser#336rdark wants to merge 1 commit intoTinder:masterfrom
rdark wants to merge 1 commit intoTinder:masterfrom
Conversation
bazel-diff 17.0.1..18.0.5 configured BazelModService.getModuleGraphJson()
with stdout=CAPTURE, stderr=CAPTURE. In Process.kt, captureAll triggers
ProcessBuilder.redirectErrorStream(true), physically merging stderr into
stdout. The captured moduleGraphJson therefore contained bazel's INFO
lines ("INFO: Invocation ID: ...", "Loading: 0 packages loaded", etc.)
prepended to the actual JSON output.
PR Tinder#330 (shipped in v18.1.0) correctly switched stderr to SILENT but
broke format compatibility: any CI pipeline re-using a base graph from
17.0.1..18.0.5 and a head graph from 18.1.0+ hits parseModuleGraph's
try/catch on the polluted side, gets emptyMap(), and cascades into
findChangedModules reporting every head-side module as "added". The
downstream queryTargetsDependingOnModules then spawns thousands of
bazel query rdeps(...) subprocesses.
Make parseModuleGraph tolerant: attempt the whole-string parse first,
and on failure retry from the first '{' to end-of-string. On second
failure fall through to the existing emptyMap() behaviour. Clean input
continues to parse in one attempt with no extra allocation.
Tests:
- ModuleGraphParserTest: positive case for stderr-prefixed input.
- StderrPollutionRegressionTest: end-to-end regression guard covering
parse, findChangedModules, and the CalculateImpactedTargetsInteractor
dispatch path. Confirms the cross-version comparison now short-circuits
to computeSimpleImpactedTargets instead of the rdeps fan-out.
65f988e to
a3cb64f
Compare
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.
Partial fix for #335
bazel-diff 17.0.1..18.0.5 configured BazelModService.getModuleGraphJson() with stdout=CAPTURE, stderr=CAPTURE. In Process.kt, captureAll triggers ProcessBuilder.redirectErrorStream(true), physically merging stderr into stdout. The captured moduleGraphJson therefore contained bazel's INFO lines ("INFO: Invocation ID: ...", "Loading: 0 packages loaded", etc.) prepended to the actual JSON output.
PR #330 (shipped in v18.1.0) correctly switched stderr to SILENT but broke format compatibility: any CI pipeline re-using a base graph from 17.0.1..18.0.5 and a head graph from 18.1.0+ hits parseModuleGraph's try/catch on the polluted side, gets emptyMap(), and cascades into findChangedModules reporting every head-side module as "added". The downstream queryTargetsDependingOnModules then spawns thousands of bazel query rdeps(...) subprocesses.
Make parseModuleGraph tolerant: attempt the whole-string parse first, and on failure retry from the first '{' to end-of-string. On second failure fall through to the existing emptyMap() behaviour. Clean input continues to parse in one attempt with no extra allocation.
Tests: