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

Ensure onStdinClose only completes for non-tty streams #1665

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## 1.50.1

### Command Line Interface

* Fix a bug where moving the `--watch` command to the background would
unexpectedly cause the command to stop running unless the standard input
stream was a TTY.

### Embedded Sass

* The JS embedded host and the embedded compiler will now properly avoid
Expand Down
8 changes: 5 additions & 3 deletions lib/src/io/interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ String? getEnvironmentVariable(String name) => throw '';
int get exitCode => throw '';
set exitCode(int value) => throw '';

/// If stdin is a TTY, returns a [CancelableOperation] that completes once it
/// closes.
/// Returns a [CancelableOperation] that completes when stdin closes.
///
/// Otherwise, returns a [CancelableOperation] that never completes.
/// Note that if stdin is a TTY, the operation never completes. This is to
/// avoid interfering with background job systems where reading from stdin
/// and then moving the process to the background would incorrectly cause
/// the job to stop.
///
/// As long as this is uncanceled, it will monopolize stdin so that nothing else
/// can read from it.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/io/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ set exitCode(int code) => process.exitCode = code;

CancelableOperation<void> onStdinClose() {
var completer = CancelableCompleter<void>();
if (isStdinTTY == true) {
if (isStdinTTY != true) {
process.stdin.on('end', allowInterop(() => completer.complete()));
}
return completer.operation;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/io/vm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ DateTime modificationTime(String path) {
String? getEnvironmentVariable(String name) => io.Platform.environment[name];

CancelableOperation<void> onStdinClose() => io.stdin.hasTerminal
? CancelableOperation.fromSubscription(io.stdin.listen(null))
: CancelableCompleter<void>().operation;
? CancelableCompleter<void>().operation
: CancelableOperation.fromSubscription(io.stdin.listen(null));

Future<Stream<WatchEvent>> watchDir(String path, {bool poll = false}) async {
var watcher = poll ? PollingDirectoryWatcher(path) : DirectoryWatcher(path);
Expand Down