Skip to content

[build-tools] Reset Gradle oom score before launch#3898

Merged
sjchmiela merged 1 commit into
mainfrom
stanley/gradle-oom-score-reset
Jul 2, 2026
Merged

[build-tools] Reset Gradle oom score before launch#3898
sjchmiela merged 1 commit into
mainfrom
stanley/gradle-oom-score-reset

Conversation

@sjchmiela

@sjchmiela sjchmiela commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Replace the delayed Gradle descendant oom_score_adj scan with an immediate shell-level reset before launching Gradle.

The worker service is protected with OOMScoreAdjust=-999, so Gradle inherits that value unless we reset it. This changes the Gradle launch wrapper to write 0 to /proc/$$/oom_score_adj before exec ./gradlew ..., which makes Gradle and its child processes inherit the default OOM score instead of the worker's protected score.

Validation

  • yarn --cwd packages/build-tools typecheck
  • yarn oxfmt --check packages/build-tools/src/android/gradle.ts packages/build-tools/src/steps/utils/android/gradle.ts
  • yarn oxlint --type-aware --import-plugin --tsconfig ./tsconfig.oxlint.json packages/build-tools/src/android/gradle.ts packages/build-tools/src/steps/utils/android/gradle.ts

@sjchmiela sjchmiela force-pushed the stanley/gradle-launch-exec branch from 7352b4f to 0d70011 Compare June 25, 2026 11:58
@sjchmiela sjchmiela force-pushed the stanley/gradle-oom-score-reset branch from 66cbf1b to 6664fc5 Compare June 25, 2026 12:00
@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 25.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.25%. Comparing base (8a66d38) to head (fcb02d1).

Files with missing lines Patch % Lines
...ages/build-tools/src/steps/utils/android/gradle.ts 25.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3898      +/-   ##
==========================================
+ Coverage   59.21%   59.25%   +0.04%     
==========================================
  Files         935      935              
  Lines       41093    41066      -27     
  Branches     8651     8652       +1     
==========================================
  Hits        24329    24329              
+ Misses      16670    16643      -27     
  Partials       94       94              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sjchmiela sjchmiela force-pushed the stanley/gradle-launch-exec branch from 0d70011 to f15ecd7 Compare June 25, 2026 12:04
@sjchmiela sjchmiela force-pushed the stanley/gradle-oom-score-reset branch from 6664fc5 to 71bce04 Compare June 25, 2026 12:06
@sjchmiela sjchmiela force-pushed the stanley/gradle-oom-score-reset branch from 71bce04 to fcb02d1 Compare July 2, 2026 09:26
@sjchmiela sjchmiela changed the base branch from stanley/gradle-launch-exec to main July 2, 2026 09:26
@sjchmiela sjchmiela added the no changelog PR that doesn't require a changelog entry label Jul 2, 2026
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

⏩ The changelog entry check has been skipped since the "no changelog" label is present.

@sjchmiela sjchmiela changed the title Reset Gradle oom score before launch [build-tools] Reset Gradle oom score before launch Jul 2, 2026
@sjchmiela sjchmiela marked this pull request as ready for review July 2, 2026 09:30
@sjchmiela sjchmiela requested a review from szdziedzic July 2, 2026 09:30
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

Subscribed to pull request

File Patterns Mentions
**/* @douglowder

Generated by CodeMention

Warning: The preamble and epilogue options in commentConfiguration are deprecated. Use template instead.

Copilot AI 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.

Pull request overview

This PR updates the Gradle launch wrappers in @expo/build-tools to reset oom_score_adj immediately (at the shell level) before exec’ing ./gradlew, preventing Gradle from inheriting the worker service’s protected OOM score.

Changes:

  • Replace the delayed descendant PID scan/override with a pre-launch /proc/$$/oom_score_adj reset in the Gradle wrapper.
  • Simplify Gradle execution to a single awaited spawn(...) and remove the old timeout-based process traversal logic.
  • Introduce a shared pattern (getGradleShellCommand) for constructing the Gradle bash wrapper command.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/build-tools/src/steps/utils/android/gradle.ts Switch step-based Gradle execution to a shell wrapper that resets oom_score_adj before exec ./gradlew.
packages/build-tools/src/android/gradle.ts Apply the same pre-launch OOM score reset approach for the main Android build Gradle runner.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +65 to +67
const oomScoreAdjPrefix =
oomScoreAdj === undefined ? '' : `echo ${oomScoreAdj} > /proc/$$/oom_score_adj || true; `;
return `${oomScoreAdjPrefix}exec ./gradlew ${gradleCommand} --profile ${verboseFlag}`;
Comment on lines +74 to +76
const oomScoreAdjPrefix =
oomScoreAdj === undefined ? '' : `echo ${oomScoreAdj} > /proc/$$/oom_score_adj || true; `;
return `${oomScoreAdjPrefix}exec ./gradlew ${gradleCommand} --profile ${verboseFlag}`;
Comment on lines +65 to 77
export function getGradleShellCommand({
gradleCommand,
oomScoreAdj,
verboseFlag,
}: {
gradleCommand: string;
oomScoreAdj?: number;
verboseFlag: string;
}): string {
const oomScoreAdjPrefix =
oomScoreAdj === undefined ? '' : `echo ${oomScoreAdj} > /proc/$$/oom_score_adj || true; `;
return `${oomScoreAdjPrefix}exec ./gradlew ${gradleCommand} --profile ${verboseFlag}`;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i know, fixing it in another pull request

@sjchmiela sjchmiela merged commit 8aa4cae into main Jul 2, 2026
14 of 19 checks passed
@sjchmiela sjchmiela deleted the stanley/gradle-oom-score-reset branch July 2, 2026 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no changelog PR that doesn't require a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants