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

Windows VM shutdown crasher #39670

Open zanderso opened 4 years ago

zanderso commented 4 years ago

After running pub run test, all tests succeed, but then it looks like the Dart VM crashes on shutdown.

Repro instructions:

This will reproduce with a Flutter checkout from top of tree. In particular I have:

Flutter 1.13.1-pre.39 • channel master • git@github.com:flutter/flutter.git
Framework • revision ec1a015045 (28 minutes ago) • 2019-12-05 22:34:06 +0100
Engine • revision fdaa7cf121
Tools • Dart 2.7.0 (build 2.7.0-dev.2.1 413867d678)

After getting a checkout under C:\flutter\:

PS C:\flutter> cd package\flutter_tools
PS C:\flutter\packages\flutter_tools> ..\..\bin\flutter --version
...
PS C:\flutter\packages\flutter_tools> ..\..\bin\cache\dart-sdk\bin\pub.bat run test .\test\commands.shard\hermetic
...
02:07 +201: All tests passed!

===== CRASH =====
ExceptionCode=-1073741819, ExceptionFlags=0, ExceptionAddress=00007FFF5F82DF23
version=2.7.0-dev.2.1.flutter-413867d678 (Wed Dec 4 11:25:19 2019 +0000) on "windows_x64"
thread=16304, isolate=(null)(0000000000000000)
Stack dump aborted because InitialRegisterCheck failed.

@a-siva @ZichangG

zanderso commented 4 years ago

Maybe due to something socket related. I'm seeing the error message:

Dart Socket ERROR: c:\b\s\w\ir\cache\builder\src\third_party\dart\runtime\bin\socket_win.cc:181: `reusePort` not supported for Windows
zichangg commented 4 years ago

I think here are 2 separate problems. The crash and socket exception are not relative.

===== CRASH =====
ExceptionCode=-1073741819, ExceptionFlags=0, ExceptionAddress=00007FFF5F82DF23
version=2.7.0-dev.2.1.flutter-413867d678 (Wed Dec 4 11:25:19 2019 +0000) on "windows_x64"
thread=16304, isolate=(null)(0000000000000000)
Stack dump aborted because InitialRegisterCheck failed.

Crash comes from this test and this.

Running this command at \flutter\packages\flutter_tools will lead to crash(commenting out other tests).

..\..\bin\cache\dart-sdk\bin\pub.bat run test .\test\commands.shard\hermetic\attach_test.dart
..\..\bin\cache\dart-sdk\bin\pub.bat run test .\test\commands.shard\hermetic\run_test.dart

I also notice there is a low chance that tests would be hanging for both tests. This is likely to be a bug in VM.

Dart Socket ERROR: c:\b\s\w\ir\cache\builder\src\third_party\dart\runtime\bin\socket_win.cc:181: `reusePort` not supported for Windows

Socket exception comes from this test.

jmagman commented 3 years ago

I know this report is old, but I saw this a few times today on LUCI builders, not sure if it's worse now?

https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket.appspot.com/8856907199425396192/+/steps/run_test.dart_for_tool_tests_shard_and_subshard_general/0/stdout

===== CRASH =====
ExceptionCode=-1073741819, ExceptionFlags=0, ExceptionAddress=00007FFF19D7DF33
version=2.12.0-263.0.dev (dev) (Tue Jan 26 11:04:06 2021 -0800) on "windows_x64"
pid=2528, thread=2732, isolate_group=(nil)(0000000000000000), isolate=(nil)(0000000000000000)
isolate_instructions=0, vm_instructions=7ff7fbfff970
Stack dump aborted because InitialRegisterCheck failed.

Is there something helpful we can be gathering in the tests to make this more actionable?

a-siva commented 3 years ago

/cc @aam

jmagman commented 3 years ago

I saw this a few times today on LUCI builders, not sure if it's worse now?

I take that back, turns out I only saw it on https://github.com/flutter/flutter/pull/74838. I merged because I thought it was a flake, but it reproduced post-submit and I had to revert it. So maybe this isn't a widespread problem, but it might be a 100% repro case to help track this down.

a-siva commented 3 years ago

So if we apply flutter/flutter#74838 and run that test we will see the crash? That would be a great help for debugging.

jmagman commented 3 years ago

@a-siva That's what I'm thinking, though I didn't have a Windows machine handy to see if I could reproduce it myself.

cd packages\flutter_tools; ..\..\bin\cache\dart-sdk\bin\pub.bat run test -rcompact -j2 --no-color --timeout=2000ms test\general.shard
aam commented 3 years ago

there is some weirdness(resulting in assert in https://github.com/dart-lang/sdk/blob/master/runtime/bin/eventhandler.h#L282) in the way how MemoryIOSink adds listener to stdio stream(when invoked from android_workflow.dart), and then test_core completeShutdown(https://github.com/dart-lang/test/blob/master/pkgs/test_core/lib/src/executable.dart#L53) fails to cancel stdio subscription.

aam commented 3 years ago

I believe with MemoryIOSink in picture we are attempting to listen to stdin twice, which is not allowed and should gracefully throw a dart exception(like it does for the repro below), yet it slips through the cracks and causes internal vm assertion(in debug build)/crash(in release build).

import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:async/async.dart';

main() async {
  final stdinLines = new StreamQueue(stdin);

  final process = await Process.start('cmd', ['/c', 'date']);
  process.stdout.transform(utf8.decoder).listen((data) { print('stdout: $data'); });
  process.stdin.addStream(stdin);
  await process.exitCode;

  stdinLines.cancel(immediate: true);
}
cnayan commented 10 months ago

I bring this issue from https://github.com/Dart-Code/Dart-Code/issues/4776#issuecomment-1786988726

I see the VS Code Dart Extension crashing in 2 ways:

  1. Hovering over a variable when debugging - This happens under special circumstances, but quite often.
  2. General crash when debugging.

Here is the crash message:

===== CRASH =====
ExceptionCode=-1073741819, ExceptionFlags=0, ExceptionAddress=00007FF65FA8FAF0
version=3.1.4 (stable) (Tue Oct 17 14:55:53 2023 +0000) on "windows_x64"
pid=15472, thread=6992, isolate_group=main(00000249FD2A2250), isolate=(nil)(0000000000000000)
os=windows, arch=x64, comp=no, sim=no
isolate_instructions=7ff65f8b6ca0, vm_instructions=7ff65f8b6cb0
fp=249fd35fab0, sp=c4d4efbd18, pc=7ff65fa8faf0
Stack dump aborted because GetAndValidateThreadStackBounds failed.
  pc 0x00007ff65fa8faf0 fp 0x00000249fd35fab0 Dart_IsPrecompiledRuntime+0x1ee370

The above crash message was produced during debugging when stepping "inside" the block body or expression body:

j = tokens.indexWhere((x) {
  return re!.hasMatch(x.word) == true;
}, idx);

Expression body:

j = tokens.indexWhere((x) => re!.hasMatch(x.word) == true, idx);

I can inspect the variables in the left pane, but not by hovering mouse over vars. This issue is consistent over certain data structures, which are pretty basic ones, but not on others. So, it works on half of the code and crashes other times.

Is this issue of mine related to the original issue posted here?

cnayan commented 10 months ago

Arrgggh!! Now I can't even put breakpoint at all!!!!! 😠

image

Crash

===== CRASH =====
ExceptionCode=-1073741819, ExceptionFlags=0, ExceptionAddress=00007FF6431EFAF0
version=3.1.5 (stable) (Tue Oct 24 04:57:17 2023 +0000) on "windows_x64"
pid=13892, thread=6740, isolate_group=main(000002350AF69A30), isolate=(nil)(0000000000000000)
os=windows, arch=x64, comp=no, sim=no
isolate_instructions=7ff643016ca0, vm_instructions=7ff643016cb0
fp=2350d09e200, sp=8e523fb7f8, pc=7ff6431efaf0
Stack dump aborted because GetAndValidateThreadStackBounds failed.
  pc 0x00007ff6431efaf0 fp 0x000002350d09e200 Dart_IsPrecompiledRuntime+0x1ee370

Versions

D:>dart --version
Dart SDK version: 3.1.5 (stable) (Tue Oct 24 04:57:17 2023 +0000) on "windows_x64"
D:>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.13.9, on Microsoft Windows [Version 10.0.19045.3570], locale en-IN)
[✓] Windows Version (Installed version of Windows is version 10 or higher)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Chrome - develop for the web
[✓] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.7.5)
[✓] Android Studio (version 2022.3)
[✓] VS Code (version 1.84.1)
[✓] Connected device (4 available)
[✓] Network resources

• No issues found!
cnayan commented 10 months ago

So, I found that the crash happens when I have a variable from outer scope being used inside an anonymous method.

Example:

    Transaction? transaction; //Outer scope var
    String capturedText; //Outer scope var

    PatternMatcher.instance.patternMatch(patterns, tokens,
          callback: (String token, String text) { // <----- Anonymous Callback Method

      // Debugging: Breakpoints hereafter crash the Dart app.

      capturedText = text; // Setting outer scope var

      //  Checking and setting outer scope var
      if (transaction == null) {
        // transaction = ...
      }

      // ...
    });

When instead of anonymous method, I switched to a private method of the class, and upgrading the local "outer scope vars" to private fields, then debugger behaved fine. No crash then.

This may help in fixing the VM.

a-siva commented 10 months ago

@cnayan not sure why you clubbed the issue you are having with debugging your app under vscode into this issue which was opened for a VM shutdown crash. A new issue would have made sense, I am going to move all your comments over to a new issue so it can be tracked over there.

cnayan commented 10 months ago

@a-siva Is this issue not a VS Code Dart plugin issue?