Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad state: Unable to start build daemon #375

Closed
Troverun opened this issue May 3, 2019 · 36 comments · Fixed by dart-lang/build#2267 or #384
Closed

Bad state: Unable to start build daemon #375

Troverun opened this issue May 3, 2019 · 36 comments · Fixed by dart-lang/build#2267 or #384

Comments

@Troverun
Copy link

Troverun commented May 3, 2019

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
Copy link
Member

grouma commented May 8, 2019

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
Copy link

ghost commented May 8, 2019

@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
Copy link

ghost commented May 8, 2019

port 0 ? ^^

@grouma
Copy link
Member

grouma commented May 8, 2019

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
Copy link

ghost commented May 8, 2019

@grouma
macOS Mojave

@grouma
Copy link
Member

grouma commented May 8, 2019

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
Copy link
Member

grouma commented May 9, 2019

Closing this one.

We should provide a better error message though:
dart-lang/build#2259

@grouma grouma closed this as completed May 9, 2019
@ghost
Copy link

ghost commented May 9, 2019

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

@grouma
Copy link
Member

grouma commented May 9, 2019

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

@ghost
Copy link

ghost commented May 9, 2019

yup i was waiting web for months

@Goolpe
Copy link

Goolpe commented May 10, 2019

@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
Copy link
Member

@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 -

dart-lang/test#100 (comment)

@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
Copy link
Member

grouma commented May 10, 2019

@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 added a commit to dart-lang/build that referenced this issue May 10, 2019
@grouma
Copy link
Member

grouma commented May 10, 2019

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
Copy link

Goolpe commented May 10, 2019

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
Copy link
Member

@grouma - do we want yet another http_multi_server here?

var server = await serve(handler, hostname, await findUnusedPort());

@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
Copy link
Member

grouma commented May 11, 2019

Published version 2.0.5 of webdev with the multi server fix.

@shakeeb1998
Copy link

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

@stemuk
Copy link

stemuk commented May 20, 2019

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 grouma reopened this May 20, 2019
@grouma
Copy link
Member

grouma commented May 20, 2019

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

@stemuk
Copy link

stemuk commented May 22, 2019

@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
Copy link
Member

grouma commented May 22, 2019

@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.

@grouma grouma reopened this May 22, 2019
@jakemac53
Copy link
Contributor

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
Copy link
Member

grouma commented May 22, 2019

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

@stemuk
Copy link

stemuk commented May 24, 2019

@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
Copy link
Member

grouma commented May 28, 2019

@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
Copy link
Member

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
Copy link

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
Copy link
Member

grouma commented Jul 22, 2019

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

@tonyclickspace
Copy link

@grouma thanks, worked like a charm

@bubnenkoff
Copy link

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
Copy link
Member

grouma commented Aug 23, 2019

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

@Timmmm
Copy link

Timmmm commented Nov 19, 2019

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 platform ddc has 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
Copy link
Member

It is indeed caused by having both build_web_compilers and build_node_compilers. See also pulyaevskiy/node-interop#72 and pulyaevskiy/node-interop#71

@u007
Copy link

u007 commented Apr 4, 2020

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 platform ddc has 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
Copy link

u007 commented May 24, 2020

running

webdev build -- --delete-conflicting-outputs

seems to work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet