-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
fix: Crash with "StreamSink is bound to stream" #1280
Comments
Hey 👋 |
I spent some time and was unable to reproduce this locally on MacOS using:
With the following sample: import 'dart:io';
import 'package:mason_logger/mason_logger.dart';
import 'package:watcher/watcher.dart';
Future<void> main() async {
final logger = Logger()..level = Level.verbose;
logger.info('Watching ${Directory.current.absolute.path} for changes');
DirectoryWatcher(Directory.current.absolute.path).events.listen((event) {
logger.detail('File system change (${event.type}): ${event.path}.');
});
} |
Hm, I'm also seeing this error when I try to log things from a web socket callback function. Do you know if there are any weird aspects to stdout and stderr when running a shelf server, or a websocket, or a directory watcher? Or all three? The issue is somehow related to time. When I make multiple changes to source files quickly, it results in the following series of desired events:
Step 5 and Step 6 are essentially happening at the same time. We don't know when the websites actually request updated versions of their files, so I fire off that notification and then immediately start rebuilding the website again, assuming a build is queued up. Through experimentation, I've found that if I wait for 1 second after telling the websites to refresh, and then I start the next build, this error doesn't seem to happen any more. I'll make some kind of adjustment on my end to try to avoid this error in general, but I'd really like to understand the root cause in the hopes that I might fully solve it. Maybe it's two things trying to access the same file at the same time? I would think the OS would transparently solve that problem. Also, if that's the problem, I would expect a very different error in a different place in the code. |
I'm not aware of any, unfortunately 😞
I'd love to better understand the root cause as well, let me know if you get to the bottom of it.
Yeah that doesn't seem likely. I would also expect a very different error if that were the case. Is the issue OS-specific? Or can you reproduce on MacOS and Windows for example? |
I haven't tried Windows because I've only got Macs. I still haven't root caused it, but I do think it has something to do with the file system. The static site generator I'm building has to do two things at the same time to be useful. It has to rebuild the static site when you make a change. It also has to serve the static site through a web server. I think, as far as I can tell, I would run a build for change A, tell the local site to refresh, the local site asks for files again, and at the same time I'm already running another build for change B. Why the FS couldn't do something reasonable in that case, I'm not sure. But I changed the build behavior so that it completes all queued builds before telling the local site to refresh and that has eliminated the vast majority of such crashes. My guess is, if the user were to manually refresh during a build, the same problem would occur. |
Description
I have a static site generator that watches a local directory for changes and runs a callback every time a file in the directory changes. I'm using Mason Logger to log output throughout the static site generator, including this method.
When the file system reports multiple file changes in quick succession, the logger seems to blow up with the error "StreamSink is bound to stream"
Steps To Reproduce
I don't have an isolated reproduction. However, I can provide some snippets of the implementation.
I watch a couple directories:
Then I have an
_onSourceFileChange
method where the error originates:That log message at the very beginning of the callback method is all that seems to be needed to trigger the error.
Expected Behavior
No error occurs and the message is logged.
Additional Context
Version: 0.2.12
Example error message:
The text was updated successfully, but these errors were encountered: