Repository navigation
Ensure JDI test VM cleanup after failed startup #992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
trancexpress
merged 1 commit into
eclipse-jdt:master
from
carstenartur:fix-jdi-test-startup-cleanup
Oct 21, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
96 changes: 96 additions & 0 deletions
96
org.eclipse.jdt.debug.jdi.tests/tests/org/eclipse/debug/jdi/tests/TestProcessCleanup.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2026 Carsten Hammer and others. | ||
| * | ||
| * This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License 2.0 | ||
| * which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Contributors: | ||
| * Carsten Hammer - initial API and implementation | ||
| *******************************************************************************/ | ||
| package org.eclipse.debug.jdi.tests; | ||
|
|
||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| /** Bounded termination of processes owned by a JDI test. */ | ||
| final class TestProcessCleanup { | ||
| private static final long EXIT_TIMEOUT_MILLIS = 5000; | ||
|
|
||
| private TestProcessCleanup() { | ||
| } | ||
|
|
||
| static void terminate(Process... processes) { | ||
| Throwable failure = null; | ||
| for (Process process : processes) { | ||
| try { | ||
| terminate(process, EXIT_TIMEOUT_MILLIS); | ||
| } catch (RuntimeException | Error e) { | ||
| if (failure == null) { | ||
| failure = e; | ||
| } else if (failure != e) { | ||
| failure.addSuppressed(e); | ||
| } | ||
| } | ||
| } | ||
| if (failure instanceof RuntimeException e) { | ||
| throw e; | ||
| } | ||
| if (failure instanceof Error e) { | ||
| throw e; | ||
| } | ||
|
trancexpress marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| private static void terminate(Process process, long timeoutMillis) { | ||
| if (process == null || !process.isAlive()) { | ||
| return; | ||
| } | ||
| // Cleanup must still run when startup was interrupted. Restore the flag below. | ||
| boolean interrupted = Thread.interrupted(); | ||
| try { | ||
| process.destroy(); | ||
| if (!interrupted) { | ||
| try { | ||
| if (process.waitFor(timeoutMillis, TimeUnit.MILLISECONDS)) { | ||
| return; | ||
| } | ||
| } catch (InterruptedException e) { | ||
| interrupted = true; | ||
| } | ||
| } | ||
| process.destroyForcibly(); | ||
| // Wait despite interruption without extending the deadline, then | ||
| // restore the interrupt status below. | ||
| long deadline = System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(timeoutMillis); | ||
| while (process.isAlive()) { | ||
|
trancexpress marked this conversation as resolved.
Resolved
|
||
| long remaining = deadline - System.nanoTime(); | ||
| if (remaining <= 0) { | ||
| throw terminationFailure(process); | ||
| } | ||
| try { | ||
| if (!process.waitFor(remaining, TimeUnit.NANOSECONDS) && process.isAlive()) { | ||
| throw terminationFailure(process); | ||
| } | ||
| } catch (InterruptedException e) { | ||
| interrupted = true; | ||
| } | ||
| } | ||
| } finally { | ||
| if (interrupted) { | ||
| Thread.currentThread().interrupt(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static IllegalStateException terminationFailure(Process process) { | ||
| String pid; | ||
| try { | ||
| pid = Long.toString(process.pid()); | ||
| } catch (UnsupportedOperationException e) { | ||
| pid = "unavailable"; | ||
| } | ||
| return new IllegalStateException("Test process " + pid + " did not terminate after destroyForcibly()"); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.