Skip to content

Fix hanging event handler for stdin. #3218

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

Merged
merged 1 commit into from
Nov 9, 2021
Merged
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
8 changes: 1 addition & 7 deletions lib/src/command/token_add.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,11 @@ class TokenAddCommand extends PubCommand {
} on FormatException catch (e) {
usageException('Invalid [hosted-url]: "$rawHostedUrl"\n'
'${e.message}');
} on TimeoutException catch (_) {
// Timeout is added to readLine call to make sure automated jobs doesn't
// get stuck on noop state if user forget to pipe token to the 'token add'
// command. This behavior might be removed.
throw ApplicationException('Token is not provided within 15 minutes.');
}
}

Future<void> _addTokenFromStdin(Uri hostedUrl) async {
final token = await stdinPrompt('Enter secret token:', echoMode: false)
.timeout(const Duration(minutes: 15));
final token = await stdinPrompt('Enter secret token:', echoMode: false);
if (token.isEmpty) {
usageException('Token is not provided.');
}
Expand Down
9 changes: 2 additions & 7 deletions lib/src/io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'dart:collection';
import 'dart:convert';
import 'dart:io';

import 'package:async/async.dart';
import 'package:cli_util/cli_util.dart'
show EnvironmentNotFoundException, applicationConfigHome;
import 'package:http/http.dart' show ByteStream;
Expand Down Expand Up @@ -562,10 +561,6 @@ final String dartRepoRoot = (() {
return path.fromUri(url);
})();

/// A line-by-line stream of standard input.
final StreamQueue<String> _stdinLines = StreamQueue(
ByteStream(stdin).toStringStream().transform(const LineSplitter()));

/// Displays a message and reads a yes/no confirmation from the user.
///
/// Returns a [Future] that completes to `true` if the user confirms or `false`
Expand All @@ -591,14 +586,14 @@ Future<String> stdinPrompt(String prompt, {bool? echoMode}) async {
final previousEchoMode = stdin.echoMode;
try {
stdin.echoMode = echoMode;
final result = await _stdinLines.next;
final result = stdin.readLineSync() ?? '';
stdout.write('\n');
return result;
} finally {
stdin.echoMode = previousEchoMode;
}
} else {
return await _stdinLines.next;
return stdin.readLineSync() ?? '';
}
}

Expand Down