Skip to content

Fix mobile gaming release validation background process cleanup for Java 21 compatibility - #39658

Open
damccorm wants to merge 8 commits into
masterfrom
users/damccorm/fix-mobile-gaming-java21
Open

Fix mobile gaming release validation background process cleanup for Java 21 compatibility#39658
damccorm wants to merge 8 commits into
masterfrom
users/damccorm/fix-mobile-gaming-java21

Conversation

@damccorm

@damccorm damccorm commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Description

In Java 20+, Thread.stop() unconditionally throws java.lang.UnsupportedOperationException (JEP 421).
Following the CI upgrade to Java 21 in #39205, the beam_PostRelease_NightlySnapshot validation workflow began timing out at 6 hours because mobilegaming-java-direct.groovy and mobilegaming-java-dataflow.groovy relied on Thread.stop() to stop background injector and leaderboard threads.

When Thread.stop() threw UnsupportedOperationException, the main test thread crashed and left the background Injector process running indefinitely as an orphan, publishing messages to Pub/Sub and hanging the build until the 6-hour execution timeout was hit.

This change:

  1. Adds runBackground, stopProcess, and stopAllBackgroundProcesses to TestScripts.groovy to manage and cleanly terminate child background processes (and their process trees) using Java's ProcessHandle APIs, with process exit verification.
  2. Registers a JVM shutdown hook in TestScripts that calls stopAllBackgroundProcesses with explicit waitFor() to guarantee all spawned background processes are terminated before JVM exit.
  3. Updates mobilegaming-java-direct.groovy and mobilegaming-java-dataflow.groovy to use t.runBackground / t.stopProcess with bounded retry loops and fresh BigQuery table cleanup.
  4. Updates quickstart-java-spark.groovy and quickstart-java-flinklocal.groovy to use mvn exec:exec with trimmed/quoted classpaths and required JVM --add-opens flags for Java 17/21 compatibility.
  5. Updates release validation version property resolution in BeamModulePlugin.groovy, release/build.gradle.kts, and .github/workflows/beam_PostRelease_NightlySnapshot.yml to properly default to project.version on nightly snapshot workflow dispatch runs.

Validation

Successful nightly snapshot validation run: https://github.com/apache/beam/actions/runs/31172410588 (completed in 48m 11s, down from timing out at 6h).


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

…ava 21 compatibility

In Java 20+, Thread.stop() unconditionally throws UnsupportedOperationException.
This caused mobile gaming validation scripts to fail when stopping background
injector and leaderboard threads, leaving the child processes running as orphans
and causing the nightly snapshot validation workflow to hang and time out at 6 hours.

This change introduces Process-based background execution and cleanup in TestScripts
to properly terminate background processes across Java versions.
@github-actions github-actions Bot added the build label Aug 6, 2026
@damccorm
damccorm marked this pull request as draft August 6, 2026 14:58
@damccorm
damccorm marked this pull request as ready for review August 6, 2026 18:10
@damccorm

damccorm commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Validated with nightly snapshot run: https://github.com/apache/beam/actions/runs/31122841120 (all Java quickstart and mobile gaming validation tasks passed in 31m 34s).

Updated the default release version and modified the description for the RELEASE input.
def jvmArgs = "--add-opens=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED"
t.run """mvn exec:exec -q -Dexec.executable=java \
-Dexec.args="${jvmArgs} -cp ${cp} org.apache.beam.examples.WordCount \
--inputFile=pom.xml --output=counts --runner=SparkRunner" """

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.

These changes fix:

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project word-count-beam: 
An exception occured while executing the Java class. class org.apache.spark.storage.StorageUtils$ (in unnamed module @0x1531e31f) 
cannot access class sun.nio.ch.DirectBuffer (in module java.base) because module java.base does not export sun.nio.ch to unnamed module

which can happen with Java 21 and was getting masked by timeouts

@damccorm

damccorm commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

R: @Abacn @Amar3tto

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @liferoad for label build.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

def pb = new ProcessBuilder(shell)
pb.directory(var.curDir)
pb.redirectErrorStream(true)
def proc = pb.start()

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.

Could we retain and check background process exit status here? _executeBackground only drains stdout, and stopProcess removes an already-exited process without inspecting its result. DirectRunner keeps leaderboard_DirectRunner_* tables, so failed Injector or LeaderBoard commands can match stale rows and report [SUCCESS]. Reproduced with both background Maven commands exiting 42 while script exited 0.

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.

Thanks - addressed this + did some other cleanup (running https://github.com/apache/beam/actions/runs/31172410588 to verify I didn't break anything with this)

@damccorm

damccorm commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Latest validation run succeeded: https://github.com/apache/beam/actions/runs/31172410588 (completed all runner validation tasks in 48m 11s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants