dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.09k stars 1.56k forks source link

[DAP] Only kill positive pids on disconnection #55209

Open elliette opened 6 months ago

elliette commented 6 months ago

On disconnection, DAP kills all pids: https://github.com/dart-lang/sdk/blob/7685ec3e0ea6b28b72823cf687d33118864ebd92/pkg/dds/lib/src/dap/adapters/mixins.dart#L41-L47

However, this set of pids contains the VM pid, which defaults to-1 if it was not set: https://github.com/dart-lang/sdk/blob/7685ec3e0ea6b28b72823cf687d33118864ebd92/pkg/vm_service/lib/src/vm_service.dart#L8570

On Linux, killing -1 is a special case that means "kill all the process that you can." We had a case where this was killing a bunch of running processes on a users machine.

DanTup commented 6 months ago

However, this set of pids contains the VM pid, which defaults to -1 if it was not set

I presume this is something mis-reporting it's PID, and not DAP recording a -1 somewhere that wasn't set? We should only record pids that are provided to DAP (such as in JSON requests from other tools, or from the a response from the VM Service).

It's not clear which of these payloads contains the offending -1 though (if it's somewhere where the field is optional, I wonder if it could be omitted instead of set to -1?)