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.08k stars 1.56k forks source link

`dart test` broken, causes frontend_server.dart.snapshot not found / SocketException: Write failed via frontend_server_client #56601

Closed mkorbel1 closed 1 week ago

mkorbel1 commented 2 weeks ago

Running a dart file via dart run bin/my_file.dart runs just fine. However, tests seem to be broken.

Reproduced with Dart v3.5.1 (in an Ubuntu 22 LTS Docker container) and v3.5.2 (on Windows 11 via chocolatey) (2 separate systems). I'm not able to reproduce on WSL2 Ubuntu on Windows 11 with v3.5.1 (a third system). I'm not sure what the special conditions are to cause this error. None of these systems have Flutter installed, just Dart. All three of these are using different projects as well. Testing on all three of these projects on all three of these systems with older versions of Dart were working fine.

Hitting the debug button in VS Code above a test or running on the command line via dart test causes an error like this:

Could not find a command named "/usr/lib/dart/bin/snapshots/frontend_server.dart.snapshot".

Usage: dart <command|dart-file> [arguments]

Global options:
-v, --verbose               Show additional command output.
    --version               Print the Dart SDK version.
    --enable-analytics      Enable analytics.
    --disable-analytics     Disable analytics.
    --suppress-analytics    Disallow analytics for this `dart *` run without changing the analytics configuration.
-h, --help                  Print this usage information.

Available commands:
  analyze    Analyze Dart code in a directory.
  compile    Compile Dart to various formats.
  create     Create a new Dart project.
  devtools   Open DevTools (optionally connecting to an existing application).
  doc        Generate API documentation for Dart projects.
  fix        Apply automated fixes to Dart source code.
  format     Idiomatically format Dart source code.
  info       Show diagnostic information about the installed tooling.
  pub        Work with packages.
  run        Run a Dart program.
  test       Run tests for a project.

Run "dart help <command>" for more information about a command.
See https://dart.dev/tools/dart-tool for detailed documentation.
Failed to load "[REMOVED TEST NAME]":
package:test_core/src/runner/vm/platform.dart 166:7  VMPlatform._spawnKernelIsolate
===== asynchronous gap ===========================
package:test_core/src/runner/vm/platform.dart 55:11  VMPlatform.load
===== asynchronous gap ===========================
package:test_core/src/runner/loader.dart 220:25      Loader.loadFile.<fn>
===== asynchronous gap ===========================
package:test_core/src/runner/load_suite.dart 99:19   new LoadSuite.<fn>.<fn>
SocketException: Write failed (OS Error: Broken pipe, errno = 32), port = 0
dart:io-patch/socket_patch.dart 1252:34                                _NativeSocket.write
dart:io-patch/socket_patch.dart 2010:15                                _RawSocket.write
dart:io-patch/socket_patch.dart 2487:18                                _Socket._write
dart:io-patch/socket_patch.dart 2222:28                                _SocketStreamConsumer.write
dart:io-patch/socket_patch.dart 2174:11                                _SocketStreamConsumer.addStream.<fn>
dart:async/zone.dart 1407:47                                           _rootRunUnary
dart:async/zone.dart 1308:19                                           _CustomZone.runUnary
dart:async/zone.dart 1217:7                                            _CustomZone.runUnaryGuarded
dart:async/stream_impl.dart 365:11                                     _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 297:7                                      _BufferingStreamSubscription._add
dart:async/stream_controller.dart 784:19                               _SyncStreamControllerDispatch._sendData
dart:async/stream_controller.dart 658:7                                _StreamController._add
dart:async/stream_controller.dart 606:5                                _StreamController.add
dart:io/io_sink.dart 154:17                                            _StreamSinkImpl.add
dart:io/io_sink.dart 287:5                                             _IOSinkImpl.write
dart:io-patch/socket_patch.dart 2320:36                                _Socket.write
dart:io/stdio.dart 401:13                                              _StdSink._write
dart:io/stdio.dart 419:5                                               _StdSink.writeln
package:frontend_server_client/src/frontend_server_client.dart 328:21  FrontendServerClient._sendCommand
package:frontend_server_client/src/frontend_server_client.dart 245:5   FrontendServerClient.accept
package:test_core/src/runner/vm/test_compiler.dart 127:30              _TestCompilerForLanguageVersion._compile
===== asynchronous gap ===========================
package:pool/pool.dart 127:14                                          Pool.withResource
===== asynchronous gap ===========================
package:test_core/src/runner/vm/platform.dart 163:22                   VMPlatform._spawnKernelIsolate
===== asynchronous gap ===========================
package:test_core/src/runner/vm/platform.dart 55:11                    VMPlatform.load
===== asynchronous gap ===========================
package:test_core/src/runner/loader.dart 220:25                        Loader.loadFile.<fn>
===== asynchronous gap ===========================
package:test_core/src/runner/load_suite.dart 99:19                     new LoadSuite.<fn>.<fn>
✖ loading [REMOVED TEST NAME]

Exited (1).

I noticed that the file /usr/lib/dart/bin/snapshots/frontend_server_aot.dart.snapshot does exist, though /usr/lib/dart/bin/snapshots/frontend_server.dart.snapshot does not exist.

Some of the output from dart info on the container system:

#### General info

- Dart 3.5.1 (stable) (None) on "linux_x64"
- on linux / Linux 5.14.21-150400.24.116-default #1 SMP PREEMPT_DYNAMIC Fri Apr 12 12:56:11 UTC 2024 (900d642)
- locale is en_US.UTF-8

#### Project info

- sdk constraint: '>=3.0.0 <4.0.0'
- dependencies: args, async, collection, dart_numerics, logging, meta, rohd, rohd_hcl, rohd_vf, yaml
- dev_dependencies: lints, resource_importer, test, test_api
dart-github-bot commented 2 weeks ago

Summary: The dart test command fails with a "frontend_server.dart.snapshot not found" error and a "SocketException: Write failed" error. This occurs on Ubuntu 22 LTS and Windows 11, but not on WSL2 Ubuntu on Windows 11. The issue appears to be related to the frontend_server.dart.snapshot file and communication between processes.

daohoangson commented 2 weeks ago

This also happened on macOS when using the latest dart binary installed by Homebrew.

Dart SDK version: 3.5.2 (stable) (Wed Aug 28 10:01:20 2024 +0000) on "macos_arm64"
mkorbel1 commented 1 week ago

This seems like a fundamental bug that for some setups dart test does not work, and I am unaware of any workaround. I'm aware of at least 2 projects where people are severely blocked by this issue since last week.

mkorbel1 commented 1 week ago

Actually, it seems that the version of the test package was being pinned to an older version. I noticed it after searching through forums and discord conversations that some other people hit similar issues. Checking dart pub outdated revealed it and then I adjusted my pubspec.yaml and fixed the issue. Leaving this note for anyone else who hits a similar problem, and closing.