Skip to content

Report more detail in VM start errors #398

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
merged 4 commits into from
Mar 17, 2022

Conversation

karlvr
Copy link
Contributor

@karlvr karlvr commented Jan 25, 2022

Resolves #397 or at least contributes to it

@ghost
Copy link

ghost commented Jan 25, 2022

CLA assistant check
All CLA requirements met.

@testforstephen testforstephen self-requested a review January 26, 2022 02:52
@testforstephen
Copy link
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 karlvr force-pushed the launch-error-reporting branch from 009ead8 to 2535217 Compare January 26, 2022 06:24
@karlvr
Copy link
Contributor Author

karlvr commented Jan 26, 2022

@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
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 karlvr force-pushed the launch-error-reporting branch from fe233f1 to 4ca695a Compare February 4, 2022 23:55
@karlvr
Copy link
Contributor Author

karlvr commented Feb 5, 2022

@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
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
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
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
Contributor Author

Choose a reason for hiding this comment

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

@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
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
Contributor Author

karlvr commented Mar 12, 2022

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

Copy link
Contributor

@testforstephen testforstephen left a comment

Choose a reason for hiding this comment

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

LGTM. @karlvr thanks for the contribution.

@testforstephen 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