Skip to content

DTD is sometimes not terminated correctly #5017

Closed

Description

@DanTup

I've seen this a few times today after closing VS Code - the process isn't being shut down.

image

Activity

  1. added this to the v3.84.0 milestone on Feb 29, 2024
  2. DanTup commented on Feb 29, 2024

    @DanTup
    MemberAuthor

    This might be something in the daemon... I can repro this with the following code:

    for (let i = 0; i < 10; i++) {
    	const process = safeSpawn(undefined, "C:\\Dev\\Tools\\Dart\\Nightly\\bin\\dart.exe", [
    		"tooling-daemon",
    		"--machine",
    	], {});
    
    	console.log(`    Spawned PID: ${process.pid}`);
    
    	process.stdout.on("data", (data: Buffer | string) => console.log(data));
    	process.stderr.on("data", (data: Buffer | string) => console.error(data));
    	process.on("exit", (code, signal) => console.warn(code, signal));
    	process.on("error", (error) => console.error(error));
    
    	await new Promise((resolve) => setTimeout(resolve, 500));
    
    	process.kill();
    	console.log(`    Killed PID: ${process.pid}`);
    }

    image

    @CoderDake FYI - I'll try to repro from Dart to eliminate NodeJS weirdness.

  3. DanTup commented on Feb 29, 2024

    @DanTup
    MemberAuthor

    Of course it doesn't happen from the equivalent Dart code 😬 I'll keep looking! My money is going to be on shell we're using to spawn it not passing across the signal. This is why many of our tools advertise pids during startup... I think maybe we should do the same here.

  4. DanTup commented on Feb 29, 2024

    @DanTup
    MemberAuthor

    Yep, enabling the shell on Windows triggers it from Dart too:

    import 'dart:convert';
    import 'dart:io';
    
    Future<void> main() async {
      final vmPath = Platform.resolvedExecutable;
      final args = [
        'tooling-daemon',
        '--machine',
      ];
    
      for (int i = 0; i < 30; i++) {
        final proc = await Process.start(vmPath, args, runInShell: true);
        print('Started ${proc.pid}');
        proc.stdout.transform(utf8.decoder).listen(print);
        proc.stderr.transform(utf8.decoder).listen(print);
    
        await Future.delayed(const Duration(milliseconds: 100));
        proc.kill();
        print('Killed ${proc.pid}');
      }
    }

    The PIDs being printed here are the shell, not the Dart process.

    @CoderDake any objections to putting the real PID inside the initial json?

    {"pid":12345,"tooling_daemon_details":{"uri":"ws://127.0.0.1:53841/","trusted_client_secret":"apGxfEl4bIDvrYxR"}}
     ^^^^^
    

    We do similar in DevTools server and other tools:

  5. DanTup commented on Feb 29, 2024

    @DanTup
    MemberAuthor

    For now, I'm going to bypass the shell for DTD - we know we don't need it. I've opened #5018 to see if we can bypass shells in other places to reduce the chance of possible leaving orphaned processes.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions