Skip to content

Commit 96404e0

Browse files
committed
Fix hanging event handler for stdin. (#3218)
Piping `stdin` to a `LineSplitter` and then using a `StreamQueue` causes event handler to wait for next characters after a line has been read. Hence, if we don't `exit()` explicitly or hit `stdin.close()` then the process will hang waiting for input on `stdin`. Using `stdin.readLineSync()` alleviates this issue. Having a timeout on prompts for tokens is nice, but only really required if we prompt while the solver is running. Which we probably won't need to do anyways, so not having a timeout is likely fine.
1 parent 0035a40 commit 96404e0

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

lib/src/command/token_add.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,11 @@ class TokenAddCommand extends PubCommand {
5757
} on FormatException catch (e) {
5858
usageException('Invalid [hosted-url]: "$rawHostedUrl"\n'
5959
'${e.message}');
60-
} on TimeoutException catch (_) {
61-
// Timeout is added to readLine call to make sure automated jobs doesn't
62-
// get stuck on noop state if user forget to pipe token to the 'token add'
63-
// command. This behavior might be removed.
64-
throw ApplicationException('Token is not provided within 15 minutes.');
6560
}
6661
}
6762

6863
Future<void> _addTokenFromStdin(Uri hostedUrl) async {
69-
final token = await stdinPrompt('Enter secret token:', echoMode: false)
70-
.timeout(const Duration(minutes: 15));
64+
final token = await stdinPrompt('Enter secret token:', echoMode: false);
7165
if (token.isEmpty) {
7266
usageException('Token is not provided.');
7367
}

lib/src/io.dart

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import 'dart:collection';
88
import 'dart:convert';
99
import 'dart:io';
1010

11-
import 'package:async/async.dart';
1211
import 'package:cli_util/cli_util.dart'
1312
show EnvironmentNotFoundException, applicationConfigHome;
1413
import 'package:http/http.dart' show ByteStream;
@@ -562,10 +561,6 @@ final String dartRepoRoot = (() {
562561
return path.fromUri(url);
563562
})();
564563

565-
/// A line-by-line stream of standard input.
566-
final StreamQueue<String> _stdinLines = StreamQueue(
567-
ByteStream(stdin).toStringStream().transform(const LineSplitter()));
568-
569564
/// Displays a message and reads a yes/no confirmation from the user.
570565
///
571566
/// Returns a [Future] that completes to `true` if the user confirms or `false`
@@ -591,14 +586,14 @@ Future<String> stdinPrompt(String prompt, {bool? echoMode}) async {
591586
final previousEchoMode = stdin.echoMode;
592587
try {
593588
stdin.echoMode = echoMode;
594-
final result = await _stdinLines.next;
589+
final result = stdin.readLineSync() ?? '';
595590
stdout.write('\n');
596591
return result;
597592
} finally {
598593
stdin.echoMode = previousEchoMode;
599594
}
600595
} else {
601-
return await _stdinLines.next;
596+
return stdin.readLineSync() ?? '';
602597
}
603598
}
604599

0 commit comments

Comments
 (0)