Prevent hangs due to bad import/export directives (#5538)
If the input test script contains a bad import, sky_shell will fail to execute main(), in which case a connection to /runner is never established and the _ServerInfo.socket never completes. This change works around this by issuing a request on /shutdown when sky_shell exits.
This commit is contained in:
@@ -21,7 +21,8 @@ import 'coverage_collector.dart';
|
|||||||
|
|
||||||
final String _kSkyShell = Platform.environment['SKY_SHELL'];
|
final String _kSkyShell = Platform.environment['SKY_SHELL'];
|
||||||
const String _kHost = '127.0.0.1';
|
const String _kHost = '127.0.0.1';
|
||||||
const String _kPath = '/runner';
|
const String _kRunnerPath = '/runner';
|
||||||
|
const String _kShutdownPath = '/shutdown';
|
||||||
|
|
||||||
String shellPath;
|
String shellPath;
|
||||||
|
|
||||||
@@ -33,20 +34,24 @@ void installHook() {
|
|||||||
|
|
||||||
class _ServerInfo {
|
class _ServerInfo {
|
||||||
final String url;
|
final String url;
|
||||||
|
final String shutdownUrl;
|
||||||
final Future<WebSocket> socket;
|
final Future<WebSocket> socket;
|
||||||
final HttpServer server;
|
final HttpServer server;
|
||||||
|
|
||||||
_ServerInfo(this.server, this.url, this.socket);
|
_ServerInfo(this.server, this.url, this.shutdownUrl, this.socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<_ServerInfo> _startServer() async {
|
Future<_ServerInfo> _startServer() async {
|
||||||
HttpServer server = await HttpServer.bind(_kHost, 0);
|
HttpServer server = await HttpServer.bind(_kHost, 0);
|
||||||
Completer<WebSocket> socket = new Completer<WebSocket>();
|
Completer<WebSocket> socket = new Completer<WebSocket>();
|
||||||
server.listen((HttpRequest request) {
|
server.listen((HttpRequest request) {
|
||||||
if (request.uri.path == _kPath)
|
if (request.uri.path == _kRunnerPath)
|
||||||
socket.complete(WebSocketTransformer.upgrade(request));
|
socket.complete(WebSocketTransformer.upgrade(request));
|
||||||
|
else if (!socket.isCompleted && request.uri.path == _kShutdownPath)
|
||||||
|
socket.completeError('Failed to start test');
|
||||||
});
|
});
|
||||||
return new _ServerInfo(server, 'ws://$_kHost:${server.port}$_kPath', socket.future);
|
return new _ServerInfo(server, 'ws://$_kHost:${server.port}$_kRunnerPath',
|
||||||
|
'ws://$_kHost:${server.port}$_kShutdownPath', socket.future);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Process> _startProcess(String mainPath, { String packages, int observatoryPort }) {
|
Future<Process> _startProcess(String mainPath, { String packages, int observatoryPort }) {
|
||||||
@@ -172,6 +177,10 @@ void main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
process.exitCode.then((_) {
|
||||||
|
WebSocket.connect(info.shutdownUrl);
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
WebSocket socket = await info.socket;
|
WebSocket socket = await info.socket;
|
||||||
StreamChannel<dynamic> channel = new StreamChannel<dynamic>(socket.map(JSON.decode), socket);
|
StreamChannel<dynamic> channel = new StreamChannel<dynamic>(socket.map(JSON.decode), socket);
|
||||||
|
|||||||
Reference in New Issue
Block a user