Skip to content

Windows directory watcher stops working after some time #37233

@jakemac53

Description

@jakemac53

Original issue on the watcher package dart-lang/tools#1713, related issue in build_runner dart-lang/webdev#436.

I created a simple repro below that uses vanilla Directory.watch. You can run each of these scripts at the same time to repro, which exposes a few issues:

  • If you start the watch script after the file modifying script is already running, then it won't see any events at all.
  • After a while (few thousand events, but not consistent), the directory watcher script simply exits.
  • The watcher script terminates in some weird way, I never see the Stream closed!! message on stdout, but the process does exit. There is no unhandled exception that surfaces either.

File modification script, edits a single file in a loop:

import 'dart:io';

void main() async {
  var i = 0;
  var file = File('out.txt');
  await file.create();
  while (true) {
    i++;
    await file.writeAsString('$i');
  }
}

Watcher script, logs watch events:

import 'dart:io';

main() async {
  var i = 0;
  await for (var event in Directory.current.watch(recursive: true)) {
    print('$i: $event');
    i++;
  }
  print('Stream closed!!');
}

As a result of this we have to use a polling watcher, which doesn't perform well.

Metadata

Metadata

Assignees

Labels

P1A high priority bug; for example, a single project is unusable or has many test failuresarea-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.library-iotype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions