dart-lang / sdk

The Dart SDK, including the VM, dart2js, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
9.94k stars 1.53k forks source link

Process.runSync() sometimes returns wildly inappropriate exit codes #47889

Open Hixie opened 2 years ago

Hixie commented 2 years ago

We (Flutter) run uname -m as part of our CI automation.

Every now and then, this exits with a non-zero exit code (though the program still runs and gives correct useful output). However, at least in the one time we've so far seen the exit code, it was outside the expected range of -255..255, it was 1080567520.

Logs: https://ci.chromium.org/ui/p/flutter/builders/try/Linux%20framework_tests_widgets/10782/overview

Source (where we call uname): https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/base/os.dart#L271

I followed this code all the way to Dart's runtime/bin/process_linux.cc but then got lost. I didn't see anything between the os.dart code above and runtime/bin/process_linux.cc that could explain the value being outside the expected range.

a-siva commented 2 years ago

what target system do you see this kind of flakiness, I ran the following code in a loop on my linux workstation and it always seems to return an exit code of 0.

import 'dart:io';

main() {
  final ProcessResult result =
    Process.runSync('uname', <String>['-m']);
  if (result.exitCode != 0) {
      print(
          'Encountered an error trying to run "uname -m":\n'
          '  exit code: ${result.exitCode}\n'
          '  stdout: ${result.stdout.trimRight()}\n'
          '  stderr: ${result.stderr.trimRight()}\n'
          );
   } else {
      print('  exit code: ${result.exitCode}\n'
              '  stdout: ${result.stdout.trimRight()}');
   }
}
Hixie commented 2 years ago

Where I saw it was on the Linux CI in Luci. I don't know how common it is or what the cause could be.

busslina commented 1 year ago

I get into same problem. I'm running command dpkg -s certbot to see if certbot is installed. In console, exit code is 0 when it is installed and 1 if not. But in Dart, running Process.runSync, exit code is always 0. This is painful.

UPDATE: Using Process.start method works fine, so I can say there is a bug in Dart Process.runSync (and maybe also in Process.run).

Dart SDK version: 2.18.5 (stable) (Tue Nov 22 15:47:29 2022 +0000) on "linux_x64". System: Debian 9.5 (WSL on Windows 10) x64