pub icon indicating copy to clipboard operation
pub copied to clipboard

`dart run test` w/o internet resulted in "Got socket error trying to find package analyzer ..."

Open srawlins opened this issue 2 years ago • 5 comments

I was on a plane, w/o internet, and tried to run dart run test test/version_test.dart in the linter repo. My pubspec.yaml was out of date compared with .dart_tool/package_config.yaml (unbeknownst to me). I think it had some dependency_overrides for analyzer and _fe_analyzer_shared:

$ ~/code/dart-sdk/sdk/xcodebuild/ReleaseX64/dart-sdk/bin/dart run test test/version_test.dart
Resolving dependencies in /Users/srawlins/code/dart-linter... (27.7s)
Got socket error trying to find package analyzer at https://pub.dev.
$ ~/code/dart-sdk/sdk/xcodebuild/ReleaseX64/dart-sdk/bin/dart --version
Dart SDK version: 3.0.0-edge.64ca878d191444046943ec81c34f6dc781a384e2 (be) (Tue Apr 4 14:34:32 2023 -0700) on "macos_x64"

More interesting info:

  1. When I landed, and tried to reproduce by turning off my Mac's WiFi, I instead got a much better failure mode, where the process would try to resolve dependencies for about 75 seconds, then give up, and run the test successfully. I was unable to reproduce the socket error.
  2. It seemed silly, but on my return flight, I tried to reproduce, as I had not captured the error to report it, and sure enough, it reproduced. I don't know what is different between plane-w/o-internet and wifi-turned-off.
  3. I found out, between flights, about dart run --no-pub, but it was not in the help text (e.g. dart run --help).

Some possible resolutions:

  • Have a timeout failure mode (like the 75 second failure mode when my WiFi was turned off), or anything other than "Got socket error; exit".
  • Add --no-pub to the help text.

If the socket thing is an issue to be resolved in dart-lang/pub, I'm happy to track this issue over there.

srawlins avatar Apr 17 '23 18:04 srawlins

cc @sigurdm any idea why pub has different behavoir here?

mit-mit avatar Apr 17 '23 18:04 mit-mit

any idea why pub has different behavior here?

My guess is that this is down differences in OS behavior when trying to open a socket with wifi on, but not connected and off. Why it would work like that I don't know.

Not sure if we have a reliable way to detect network availability on desktop. If WIFI is off we should ideally not wait at all, but just give up.

To me the "socket error" seems easier to understand than the long wait - but maybe I'm misunderstanding something.

Also I don't understand why it runs the tests after giving up in the WIFI-off case. I would have expected it to halt.

sigurdm avatar Apr 18 '23 07:04 sigurdm

When I turn off WIFI on my mac I get a 26 second wait, and then a socket error:

> dart run test
Resolving dependencies in /Users/sigurdm/projects/blah... (26.9s)
Got socket error trying to find package test at https://pub.dev.

sigurdm avatar Apr 18 '23 07:04 sigurdm

Also I don't understand why it runs the tests after giving up in the WIFI-off case. I would have expected it to halt.

Mmm you may be correct. I may be misremembering that.

srawlins avatar Apr 18 '23 15:04 srawlins

We should probably implement platform-specific internet-availability checks, and if we detect that no internet is available, don't wait for a time-out, but instead attempt to resolve with --offline.

sigurdm avatar Sep 14 '23 09:09 sigurdm