Skip to content
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

Debug: Provide graceful shutdown on debug stop action #1274

Open
circlesmiler opened this issue Dec 15, 2022 · 7 comments
Open

Debug: Provide graceful shutdown on debug stop action #1274

circlesmiler opened this issue Dec 15, 2022 · 7 comments
Assignees
Milestone

Comments

@circlesmiler
Copy link

circlesmiler commented Dec 15, 2022

When stopping a debugging session, the application will be killed immediately without running shutdownHook code. There is the same discussion in the GO Lang project (golang/vscode-go#120).

It would be nice to have the chance to decide, how the application will be killed (SIGKILL vs SIGTERM). Both are valid use-cases. Maybe it's even possible to have options on the STOP button of the debug panel. As we have multi-project workspaces, it really depends on the application (even situation) what you need.

Environment
  • Operating System: MacOS (But same on Windows/Linux)
  • JDK version: 11
  • Visual Studio Code version: 1.74.0
  • Java extension version: v0.25.7
  • Java Debugger extension version: v0.47.0
Steps To Reproduce
  1. Made a java application with an shutdownHook (Runtime.addShutdownHook)
  2. Start the application
  3. Stop the application by clicking the STOP button in the debug panel.
Current Result

The shutdownHook will not be executed.

Expected Result

The shutdownHook will be executed. (At least if the user chooses to)

Additional Informations

N/A

@testforstephen
Copy link
Contributor

Since the debugger is using JDI VirtualMachine#exit(int) API to stop the target debuggee, the debugger has little control over this behavior. I'm wondering if other IDEs support the capability you declare?

@circlesmiler
Copy link
Author

@testforstephen IntelliJ does. 🤷‍♂️ We noticed because our Spring Boot project does some clean up stuff, when shutting down. The IntelliJ users have no problem, but VSCode users have. I'm not sure how IntelliJ is doing it.

@stefanrybacki
Copy link

@testforstephen Eclipse also shuts down application gracefully

@robaho
Copy link

robaho commented Jul 20, 2023

The debug panel should work like the Node.js debug extension. The first press of STOP uses SIGINT. The second press of stop sends SIGKILL.

The 'restart' command in the debug panel should work similarly - or if the SIGINT doesn't kill the process in X seconds (configurable in the launch.json) a SIGKILL is sent. Then when the process dies and new one is created.

This is a serious problem because not running shutdown hooks can leave many applications in a corrupted state.

Note too, that if you kill the process using the 'delete icon' in the terminal panel it shuts down gracefully - so it seems this should be rather straightforward to fix.

@robaho
Copy link

robaho commented Jul 20, 2023

I believe the offending code is here - which is in the Java debug server.

This should first attempt to get the Process object, and if non-null, use process.destroy() else use the vm.exit()

@testforstephen testforstephen added this to the Backlog milestone Jul 21, 2023
@totszwai
Copy link

totszwai commented Mar 19, 2024

Yeah, I second this, I couldn't test my graceful shutdown procedure (without some manual hacks) through VS2022 debugging.
Namely, my process starts other subprocesses and during its shutdown, is supposed to kill the child processes, but right now the parent just dies immediately leaving the child hanging and need to be killed via task manager.

Edit:
Actually, I partly take that back. There is a way to do graceful shutdown, but, it would be nice for the stop button in Visual Studio to try doing a proper shutdown too.

image

@mozhuanzuojing
Copy link

现在有消息吗?

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

No branches or pull requests

6 participants