dart-lang / webdev

A CLI for Dart web development.
https://pub.dev/packages/webdev
212 stars 75 forks source link

Bad state: Unable to start build daemon #375

Closed Troverun closed 5 years ago

Troverun commented 5 years ago

webdev serve command

[WARNING] Deleted previous snapshot due to missing asset graph.
[INFO] Unhandled exception:erver/src/utils.dart               supportsIPv6.<fn>[2Kn[2K[2KKt, port = 0[2K
Bad state: Unable to start build daemon.
#0      _handleDaemonStartup (package:build_daemon/client.dart:52:5)
<asynchronous suspension>
#1      BuildDaemonClient.connect (package:build_daemon/client.dart:142:11)
<asynchronous suspension>
#2      connectClient (package:webdev/src/daemon_client.dart:17:23)
#3      _startBuildDaemon (package:webdev/src/serve/dev_workflow.dart:24:18)
<asynchronous suspension>
#4      DevWorkflow.start (package:webdev/src/serve/dev_workflow.dart:165:24)
<asynchronous suspension>
#5      ServeCommand.run (package:webdev/src/command/serve_command.dart:110:27)
<asynchronous suspension>
#6      CommandRunner.runCommand (package:args/command_runner.dart:196:27)
<asynchronous suspension>
#7      _CommandRunner.runCommand (package:webdev/src/webdev_command_runner.dart:38:24)
<asynchronous suspension>
#8      CommandRunner.run.<anonymous closure> (package:args/command_runner.dart:111:29)
#9      new Future.sync (dart:async/future.dart:224:31)
#10     CommandRunner.run (package:args/command_runner.dart:111:11)
#11     run (package:webdev/src/webdev_command_runner.dart:19:56)
#12     main (file:///C:/Users/Administrator/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/webdev-2.0.4/bin/webdev.dart:17:22)
<asynchronous suspension>
#13     _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:298:32)
#14     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:171:12)
[WARNING] Deleted previous snapshot due to missing asset graph.

How to do?

grouma commented 5 years ago

What version of webdev are you using? (run webdev --version)

What version of build_runner and build_daemon are you using in your application? (Can be found in pubspec.lock)

You should be able to run the command pub run build_runner daemon in your application workspace. If that doesn't work please provide the error message.

ghost commented 5 years ago

@grouma

2.0.4

  build_daemon:
    dependency: transitive
    description:
      name: build_daemon
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.6.0"

  build_runner:
    dependency: "direct dev"
    description:
      name: build_runner
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.4.0"

  build_runner_core:
    dependency: transitive
    description:
      name: build_runner_core
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.0.5"
pub run build_runner daemon

SocketException: Failed to create server socket (OS Error: Can't assign requested address, errno = 49), address = localhost, port = 0
dart:_http                                             HttpServer.bind
package:shelf/shelf_io.dart 45:20                      serve
package:build_daemon/src/server.dart 82:21             Server.listen
package:build_daemon/src/daemon.dart 71:30             Daemon.start
dart:async                                             _AsyncAwaitCompleter.start
package:build_daemon/src/daemon.dart 58:21             Daemon.start
package:build_runner/src/entrypoint/daemon.dart 74:20  DaemonCommand.run
dart:async                                             _completeOnAsyncReturn
package:build_runner/src/daemon/asset_server.dart      AssetServer.run
dart:async                                             _completeOnAsyncReturn
package:http_multi_server/http_multi_server.dart       HttpMultiServer._loopback
ghost commented 5 years ago

port 0 ? ^^

grouma commented 5 years ago

Thanks for the error message. That will definitely help figure out what's going on.

As for the 0 port, it's intentional: https://github.com/dart-lang/build/blob/master/build_daemon/lib/src/server.dart#L82

I do not believe it is documented but I thought the 0 port indicates that any open port should be used.

What operating system are you using?

ghost commented 5 years ago

@grouma macOS Mojave

grouma commented 5 years ago

Looks like it is a local error. A restart or this can solve it: http://codefromabove.com/quickies/osx-cant-assign-requested-address-code49/

grouma commented 5 years ago

Closing this one.

We should provide a better error message though: https://github.com/dart-lang/build/issues/2259

ghost commented 5 years ago

reboot / ifconfig did not fix things but i removed some entries in /etc/hosts and it fixed things

grouma commented 5 years ago

Glad you got it working. Enjoy the Flutter Web preview!

ghost commented 5 years ago

yup i was waiting web for months

Goolpe commented 5 years ago

@grouma I have the same error on Windows 7 (x64). Restart didn't help

SocketException: Failed to create server socket (OS Error: Failed to start accept), address = localhost, port = 0
dart:_http                                             HttpServer.bind
serve
package:shelf/shelf_io.dart:45
Server.listen
package:build_daemon/src/server.dart:82
Daemon.start
package:build_daemon/src/daemon.dart:71
dart:async                                             _AsyncAwaitCompleter.start
Daemon.start
package:build_daemon/src/daemon.dart:58
DaemonCommand.run
package:build_runner/…/entrypoint/daemon.dart:74
dart:async                                             _completeOnAsyncReturn
package:build_runner/src/daemon/asset_server.dart      AssetServer.run
dart:async                                             _completeOnAsyncReturn
package:http_multi_server/http_multi_server.dart       HttpMultiServer._loopback
dart:async                                             _completeOnAsyncReturn
package:http_multi_server/src/utils.dart               supportsIPv6.<fn>
Unhandled exception:
Bad state: Unable to start build daemon.
#0      _handleDaemonStartup
package:build_daemon/client.dart:52
<asynchronous suspension>
#1      BuildDaemonClient.connect
package:build_daemon/client.dart:142
<asynchronous suspension>
#2      connectClient  (package:webdev/src/daemon_client.dart:17:23)
#3      _startBuildDaemon  (package:webdev/src/serve/dev_workflow.dart:24:18)
<asynchronous suspension>
#4      DevWorkflow.start  (package:webdev/src/serve/dev_workflow.dart:165:24)
<asynchronous suspension>
#5      DaemonCommand.run  (package:webdev/src/command/daemon_command.dart:77:36)
<asynchronous suspension>
#6      CommandRunner.runCommand
package:args/command_runner.dart:196
<asynchronous suspension>
#7      _CommandRunner.runCommand  (package:webdev/src/webdev_command_runner.dart:38:24)
<asynchronous suspension>
#8      CommandRunner.run.<anonymous closure>
package:args/command_runner.dart:111
#9      new Future.sync  (dart:async/future.dart:224:31)
#10     CommandRunner.run
package:args/command_runner.dart:111
#11     run  (package:webdev/src/webdev_command_runner.dart:19:56)
#12     main
..\…\bin\webdev.dart:17
<asynchronous suspension>
#13     _startIsolate.<anonymous closure>  (dart:isolate-patch/isolate_patch.dart:298:32)
#14     _RawReceivePortImpl._handleMessage  (dart:isolate-patch/isolate_patch.dart:171:12)
[√] Flutter (Channel dev, v1.5.8, on Microsoft Windows [Version 6.1.7601], locale ru-RU)
    • Flutter version 1.5.8 at C:\flutter
    • Framework revision 0ba67226ee (2 weeks ago), 2019-04-24 17:18:28 -0700
    • Engine revision c63d1cf9c9
    • Dart version 2.3.0 (build 2.3.0-dev.0.1 1f1592edce)

[√] VS Code (version 1.33.1)
    • VS Code at C:\Users\Freedlee\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.0.1

  webdev: 2.0.4
  build_runner: ^1.4.0
  build_web_compilers: ^2.0.0
natebosch commented 5 years ago

@Goolpe - Here is a similar case where someone hit this issue, and it had to do with localhost resolving to an IPv6 address which wasn't working -

https://github.com/dart-lang/test/issues/100#issuecomment-99302170

@grouma should this work with IPv6? Should we be using loopbackIPv4?

https://github.com/dart-lang/build/blob/791e7e4855764fc74a31bdbe2c26c7cfe631e454/build_daemon/lib/src/server.dart#L82

grouma commented 5 years ago

@natebosch It does look like an IPv6 issue however we haven't run into this before.

That being said we should probably update the logic so that it is similar to this: https://github.com/dart-lang/webdev/blob/master/dwds/lib/service.dart#L85

grouma commented 5 years ago

This should now be resolved. Please pub upgrade to get the latest version of build_daemon. You should see version 0.6.1.

If you run into further issues please reopen.

A better error message will be provided when we publish version 1.0.0 of build_daemon.

Goolpe commented 5 years ago

Now build_daemon 0.6.1, but I get this:

build_runner: Setting up file watchers...
build_runner: Setting up file watchers completed, took 6ms
Registering build targets...
Starting initial build...
Unhandled exception:
SocketException: Failed to create server socket (OS Error: Failed to start accept), address = localhost, port = 58133
#0      _NativeSocket.bind  (dart:io-patch/socket_patch.dart:591:7)
<asynchronous suspension>
#1      _RawServerSocket.bind  (dart:io-patch/socket_patch.dart:1206:26)
#2      _ServerSocket.bind  (dart:io-patch/socket_patch.dart:1466:29)
#3      ServerSocket.bind  (dart:io-patch/socket_patch.dart:1457:26)
#4      _HttpServer.bind  (dart:_http/http_impl.dart:2520:25)
#5      HttpServer.bind (dart:_http:227:19)
#6      serve
package:shelf/shelf_io.dart:45
<asynchronous suspension>
#7      DevTools.start  (package:webdev/src/serve/debugger/devtools.dart:53:24)
<asynchronous suspension>
#8      _startDevTools  (package:webdev/src/serve/dev_workflow.dart:97:35)
<asynchronous suspension>
#9      DevWorkflow.start  (package:webdev/src/serve/dev_workflow.dart:170:26)
<asynchronous suspension>
#10     DaemonCommand.run  (package:webdev/src/command/daemon_command.dart:77:36)
<asynchronous suspension>
#11     CommandRunner.runCommand
package:args/command_runner.dart:196
<asynchronous suspension>
#12     _CommandRunner.runCommand  (package:webdev/src/webdev_command_runner.dart:38:24)
<asynchronous suspension>
#13     CommandRunner.run.<anonymous closure>
package:args/command_runner.dart:111
#14     new Future.sync  (dart:async/future.dart:224:31)
#15     CommandRunner.run
package:args/command_runner.dart:111
#16     run  (package:webdev/src/webdev_command_runner.dart:19:56)
#17     main
..\…\bin\webdev.dart:17
<asynchronous suspension>
#18     _startIsolate.<anonymous closure>  (dart:isolate-patch/isolate_patch.dart:298:32)
#19     _RawReceivePortImpl._handleMessage  (dart:isolate-patch/isolate_patch.dart:171:12)

I try to restart, recreate, but error is the same.(only by webdev serve- port replace to 8080)

natebosch commented 5 years ago

@grouma - do we want yet another http_multi_server here? https://github.com/dart-lang/webdev/blob/7d14c3b21a2e0e85dc9764a49050088d714f7064/webdev/lib/src/serve/debugger/devtools.dart#L53

@Goolpe - in the short term you may be able to work around this yourself by changing the host entry for localhost in your hosts file to 127.0.0.1 assuming that it's currently an IPv6 address...

grouma commented 5 years ago

Published version 2.0.5 of webdev with the multi server fix.

shakeeb1998 commented 5 years ago

@grouma I am still facing this issue though I have everything up to date

stemuk commented 5 years ago

I can report that just like @shakeeb1998 I am still facing this issue as well even with everything upgraded to its latest version. A restart does only fix the issue for the first use of webdev serve. If the command is used a second time, the problem prevails.

grouma commented 5 years ago

When the webdev command fails the second time what output do you see when you pub run build_runner daemon in your workspace?

stemuk commented 5 years ago

@grouma Sorry the late reply! This is the output that I get after the first input of webdev serve:

stefan@thinkpad:~/projects/studilabs$ webdev serve
[WARNING] Deleted previous snapshot due to missing asset graph.
[INFO] Please file an issue with reproduction steps at https://github.com/dart-l[INFO] Failed to watch path, path = '/home/stefan/projects/studilabs/.git/object[INFO] Serving `web` on http://localhost:8080
WebSocketChannelException: WebSocketChannelException: SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 55604
grouma commented 5 years ago

@stemuk what do you get when you run pub run build_runner daemon and webdev serve --verbose?

Also what version of build_runner, build_daemon and webdev do you have? Finally what OS are you running?

cc @jakemac53

It looks like the root cause is due to a file watching issue here: https://github.com/dart-lang/build/blob/184f1f5479898731dede72c6286835d4b8b7aa3f/build_runner/lib/src/daemon/daemon_builder.dart#L184-L188

My guess is that the PollingDirectoryWatcher causes an issue after the build_daemon "successfully" starts up. This causes issue with webdev connecting to the websocket hosted by the build_daemon. Any idea on why the .git directory can't be watched?

Update:

It looks like @stemuk is running on Linux so they shouldn't be using the PollingDirectoryWatcher. It's really odd that they are creating a watcher within a .git directory. A full exception will be helpful. I wonder if they have a dependency_override in their pubspec that is pointing to this odd path.

jakemac53 commented 5 years ago

No ideas on the file watching, other than if the polling watcher (assuming windows) could be exhausting all available file handles or something else like that, but that seems unlikely?

grouma commented 5 years ago

I did a quick review of the watcher code. I believe there is a race condition. Resolving this should help: https://github.com/dart-lang/watcher/issues/69

stemuk commented 5 years ago

@grouma I am running my development on Ubuntu 16.04 and webdev version 2.0.5. If it is of any help, the projects pubspec.yaml file looks like:

name: studilabs
description: An app built using Flutter for web

environment:
  # You must be using Flutter >=1.5.0 or Dart >=2.3.0
  sdk: '>=2.3.0-dev.0.1 <3.0.0'

dependencies:
  flutter_web: any
  flutter_web_ui: any

dev_dependencies:
  build_runner: any
  build_web_compilers: '>=1.0.0 <2.0.0'
  pedantic: ^1.0.0

dependency_overrides:
  flutter_web:
    git:
      url: https://github.com/flutter/flutter_web
      path: packages/flutter_web
  flutter_web_ui:
    git:
      url: https://github.com/flutter/flutter_web
      path: packages/flutter_web_ui
grouma commented 5 years ago

@stemuk

Nothing out of the ordinary. I replicated your setup and didn't have any issues. What happens when you run pub run build_runner daemon in your workspace? Also we will soon provide better error messages with version 2.0.6 of webdev.

natebosch commented 5 years ago

I think we've fixed the known issues here and we've improved logging - if anyone is still running in to trouble feel free to update with the current output you're seeing and we can take another look.

tonyclickspace commented 5 years ago

Encountering this issue now - looks like the build_runner moving to build_daemon 2.0.0 reintroduced problems. Issue persists after a computer reboot too. macOS Mojave, 10.14.5 webdev 2.3.0 build_daemon 2.0.0 build_runner 1.6.2

Unhandled exception:
Bad state: Unable to start build daemon.
#0      _handleDaemonStartup (package:build_daemon/client.dart:82:5)
<asynchronous suspension>
#1      BuildDaemonClient.connect (package:build_daemon/client.dart:183:11)
<asynchronous suspension>
#2      connectClient (package:webdev/src/daemon_client.dart:17:23)
#3      BuildCommand.run (package:webdev/src/command/build_command.dart:57:26)
<asynchronous suspension>
#4      CommandRunner.runCommand (package:args/command_runner.dart:197:27)
<asynchronous suspension>
#5      _CommandRunner.runCommand (package:webdev/src/webdev_command_runner.dart:38:24)
<asynchronous suspension>
#6      CommandRunner.run.<anonymous closure> (package:args/command_runner.dart:112:25)
#7      new Future.sync (dart:async/future.dart:224:31)
#8      CommandRunner.run (package:args/command_runner.dart:112:14)
#9      run (package:webdev/src/webdev_command_runner.dart:19:56)
#10     main (file:///Users/tonydowney/.pub-cache/hosted/pub.dartlang.org/webdev-2.3.0/bin/webdev.dart:17:22)
<asynchronous suspension>
#11     _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299:32)
#12     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
Process finished with exit code 255
grouma commented 5 years ago

pub run build_runner clean will resolve your issue. I believe your build script is cached in a problematic state.

tonyclickspace commented 5 years ago

@grouma thanks, worked like a charm

bubnenkoff commented 5 years ago

Same issue

PS D:\code\flutter\app1\app_1> pub run build_runner clean
Could not find a file named "pubspec.yaml" in "C:\Users\bubnenkov\AppData\Roaming\Pub\Cache\hosted\pub.dartlang.org\provider-3.1.0".
grouma commented 5 years ago

@bubnenkoff it seems like your pub cache is corrupted. Try running pub cache repair

Timmmm commented 4 years ago

I now get this even after pub run build_runner clean and pub cache repair. Can you at least improve the error message?

I get sooooo many random internal errors from webdev and Dart in general... I really want to like it but seeing "It failed. You're on your own." for the Nth time leaves quite a bad impression. :-(

For instance, after trying pub run build_runner clean, webdev still produced this error. I though "ok I'll try pub cached repair", but that then produced another error that it couldn't recompile stagehand or webdev. It feels like an endless bug yak shave.

For the second bug, running pub cache repair again, and then pub global activate webdev fixed it. But I still get the original error.

I suspect the actual error is The platformddchas already been registered....

[SEVERE] The platform `ddc`, has already been registered.

[SEVERE] Failed to instantiate builder for collection with configuration:
{}
Unhandled exception:
Bad state: Unable to start build daemon.

Which I guess is related to the fact that I have this in my pubspec.yaml:

  build_web_compilers: ^2.1.0
  build_node_compilers: ^0.2.3

But if I remove either of them I get some error or other. The shaving continues...

natebosch commented 4 years ago

It is indeed caused by having both build_web_compilers and build_node_compilers. See also https://github.com/pulyaevskiy/node-interop/issues/72 and https://github.com/pulyaevskiy/node-interop/pull/71

u007 commented 4 years ago

I now get this even after pub run build_runner clean and pub cache repair. Can you at least improve the error message?

I get sooooo many random internal errors from webdev and Dart in general... I really want to like it but seeing "It failed. You're on your own." for the Nth time leaves quite a bad impression. :-(

For instance, after trying pub run build_runner clean, webdev still produced this error. I though "ok I'll try pub cached repair", but that then produced another error that it couldn't recompile stagehand or webdev. It feels like an endless bug yak shave.

For the second bug, running pub cache repair again, and then pub global activate webdev fixed it. But I still get the original error.

I suspect the actual error is The platformddchas already been registered....

[SEVERE] The platform `ddc`, has already been registered.

[SEVERE] Failed to instantiate builder for collection with configuration:
{}
Unhandled exception:
Bad state: Unable to start build daemon.

Which I guess is related to the fact that I have this in my pubspec.yaml:

  build_web_compilers: ^2.1.0
  build_node_compilers: ^0.2.3

But if I remove either of them I get some error or other. The shaving continues...

did not work for me

u007 commented 4 years ago

running

webdev build -- --delete-conflicting-outputs

seems to work