Skip to content

Report more detail in VM start errors - #398

Merged
Jinbo Wang (testforstephen) merged 4 commits into
microsoft:mainfrom
karlvr:launch-error-reporting
Mar 17, 2022
Merged

Jinbo Wang (testforstephen) merged 4 commits into
microsoft:mainfrom
karlvr:launch-error-reporting

Conversation

@karlvr

Copy link
Copy Markdown
Contributor

Resolves #397 or at least contributes to it

@ghost

Deleted user (ghost) commented Jan 25, 2022 •

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

@testforstephen

Copy link
Copy Markdown
Contributor

This is a nice improvement.

Currently the CI reports some checkstyle errors, you can run checkstyle check via cmd ./mvnw checkstyle:check in local machine.

Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[1] (header) RegexpHeader: Line does not match expected header line of '^/\*+$'.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[10] (regexp) RegexpSingleline: Line has trailing spaces.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[10,1] (whitespace) FileTabCharacter: Line contains a tab character.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[11] (indentation) Indentation: 'member def type' has incorrect indentation level 8, expected level should be 4.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[11,1] (whitespace) FileTabCharacter: Line contains a tab character.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[12] (indentation) Indentation: 'member def type' has incorrect indentation level 8, expected level should be 4.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[12,1] (whitespace) FileTabCharacter: Line contains a tab character.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[13] (indentation) Indentation: 'member def type' has incorrect indentation level 8, expected level should be 4.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[13,1] (whitespace) FileTabCharacter: Line contains a tab character.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[14] (indentation) Indentation: 'member def type' has incorrect indentation level 8, expected level should be 4.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[14,1] (whitespace) FileTabCharacter: Line contains a tab character.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[16] (indentation) Indentation: 'ctor def modifier' has incorrect indentation level 8, expected level should be 4.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[16,1] (whitespace) FileTabCharacter: Line contains a tab character.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[17] (indentation) Indentation: 'ctor def' child has incorrect indentation level 16, expected level should be 8.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[17,1] (whitespace) FileTabCharacter: Line contains a tab character.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[18] (indentation) Indentation: 'ctor def' child has incorrect indentation level 16, expected level should be 8.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[18,1] (whitespace) FileTabCharacter: Line contains a tab character.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[19] (indentation) Indentation: 'ctor def' child has incorrect indentation level 16, expected level should be 8.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[19,1] (whitespace) FileTabCharacter: Line contains a tab character.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[20] (indentation) Indentation: 'ctor def' child has incorrect indentation level 16, expected level should be 8.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[20,1] (whitespace) FileTabCharacter: Line contains a tab character.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[21] (indentation) Indentation: 'ctor def' child has incorrect indentation level 16, expected level should be 8.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[21,1] (whitespace) FileTabCharacter: Line contains a tab character.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[22] (indentation) Indentation: 'ctor def rcurly' has incorrect indentation level 8, expected level should be 4.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[22,1] (whitespace) FileTabCharacter: Line contains a tab character.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[24] (indentation) Indentation: 'method def modifier' has incorrect indentation level 8, expected level should be 4.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[24,1] (whitespace) FileTabCharacter: Line contains a tab character.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[25] (indentation) Indentation: 'method def' child has incorrect indentation level 16, expected level should be 8.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[25,1] (whitespace) FileTabCharacter: Line contains a tab character.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[26] (indentation) Indentation: 'method def rcurly' has incorrect indentation level 8, expected level should be 4.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[26,1] (whitespace) FileTabCharacter: Line contains a tab character.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[28] (indentation) Indentation: 'method def modifier' has incorrect indentation level 8, expected level should be 4.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[28,1] (whitespace) FileTabCharacter: Line contains a tab character.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[29] (indentation) Indentation: 'method def' child has incorrect indentation level 16, expected level should be 8.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[29,1] (whitespace) FileTabCharacter: Line contains a tab character.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[30] (indentation) Indentation: 'method def rcurly' has incorrect indentation level 8, expected level should be 4.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[30,1] (whitespace) FileTabCharacter: Line contains a tab character.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[32] (indentation) Indentation: 'method def modifier' has incorrect indentation level 8, expected level should be 4.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[32,1] (whitespace) FileTabCharacter: Line contains a tab character.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[33] (indentation) Indentation: 'method def' child has incorrect indentation level 16, expected level should be 8.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[33,1] (whitespace) FileTabCharacter: Line contains a tab character.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[34] (indentation) Indentation: 'method def rcurly' has incorrect indentation level 8, expected level should be 4.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[34,1] (whitespace) FileTabCharacter: Line contains a tab character.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[36] (indentation) Indentation: 'method def modifier' has incorrect indentation level 8, expected level should be 4.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[36,1] (whitespace) FileTabCharacter: Line contains a tab character.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[37] (indentation) Indentation: 'method def' child has incorrect indentation level 16, expected level should be 8.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[37,1] (whitespace) FileTabCharacter: Line contains a tab character.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[38] (indentation) Indentation: 'method def rcurly' has incorrect indentation level 8, expected level should be 4.
Error:  src/main/java/com/microsoft/java/debug/core/LaunchException.java:[38,1] (whitespace) FileTabCharacter: Line contains a tab character.

@karlvr

Copy link
Copy Markdown
Contributor Author

Jinbo Wang (@testforstephen) thank you. Just a few checkstyle errors there! I've force-pushed a fix for them to keep the commit history clean.

I have been investigating terminating early if the process exits... I don't know if there are any clever tricks to do that here, I haven't done any work with Futures! I'm sort of looking for a "race" between the Process exiting and the debug connection accept returning... also given that accept will timeout. Any suggestions welcome otherwise I'll continue to experiment.

@testforstephen

Copy link
Copy Markdown
Contributor

Process process = Runtime.getRuntime().exec(cmds, envVars, workingDir);
VirtualMachineImpl vm;
try {
vm = (VirtualMachineImpl) listenConnector.accept(args);
} catch (IOException | IllegalConnectorArgumentsException e) {
process.destroy();
throw new VMStartException(String.format("VM did not connect within given time: %d ms", ACCEPT_TIMEOUT), process);
}

How about using process.onExit() to watch the exit event and return early?

        process.onExit().whenCompleteAsync((p, ex) -> {
            if (vm == null) {  // When the debug connection is not set up yet.
                  listenConnector.stopListening(args);
                  ...
            }
        });

@karlvr

Copy link
Copy Markdown
Contributor Author

Jinbo Wang (@testforstephen) I have pushed some additional work that detects early termination of the launched process, so we no longer have to wait for the timeout to report the error.

@testforstephen

Copy link
Copy Markdown
Contributor

Just came back from vacation, I will find some time this week to review this PR?

BTW, do you have any sample project to help reproduce the issue at #397? thanks.

final CompletableFuture<VirtualMachineImpl> result = new CompletableFuture<>();

/* Listen for the debug connection from the Java process */
ForkJoinPool.commonPool().execute(() -> {

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.

Prefer to use CompletableFuture.runAsync(...)

});

/* Wait for the Java process to exit; if it exits before the debug connection is made, report it as an error. */
process.onExit().thenAcceptAsync(theProcess -> {

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.

In real world, is there any use case that the process has exited but the listenConnector is still keeping the connection and not terminate?

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.

Jinbo Wang (@testforstephen) I'm not sure. I have seen socket-related things not detecting disconnection etc. I tried to tidy everything up in each case. Is there a particular case that you're thinking may be overkill?

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.

I see process.onExit() is hit immediately with your sample. Looks good.

@karlvr

Copy link
Copy Markdown
Contributor Author

Jinbo Wang (@testforstephen) I hope you had a great vacation. I have added a very simple example of reproducing the error to #397.

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.

LGTM. Karl von Randow (@karlvr) thanks for the contribution.

@testforstephen
Jinbo Wang (testforstephen) merged commit 7f6f76b into microsoft:main Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VM launch failure doesn't report a useful error

2 participants