in lib/src/driver/driver.dart [133:176]
void _runWorker(Process worker, _WorkAttempt attempt) {
var rescheduled = false;
runZonedGuarded(() async {
var connection = _workerConnections[worker]!;
connection.writeRequest(attempt.request);
var responseFuture = connection.readResponse();
if (attempt.trackWork != null) {
attempt.trackWork!(responseFuture);
}
var response = await responseFuture;
// It is possible for us to complete with an error response due to an
// unhandled async error before we get here.
if (!attempt.responseCompleter.isCompleted) {
if (response.exitCode == EXIT_CODE_BROKEN_PIPE) {
rescheduled = _tryReschedule(attempt);
if (rescheduled) return;
stderr.writeln('Failed to run request ${attempt.request}');
response = WorkResponse()
..exitCode = EXIT_CODE_ERROR
..output =
'Invalid response from worker, this probably means it wrote '
'invalid output or died.';
}
attempt.responseCompleter.complete(response);
_cleanUp(worker);
}
}, (e, s) {
// Note that we don't need to do additional cleanup here on failures. If
// the worker dies that is already handled in a generic fashion, we just
// need to make sure we complete with a valid response.
if (!attempt.responseCompleter.isCompleted) {
rescheduled = _tryReschedule(attempt);
if (rescheduled) return;
var response = WorkResponse()
..exitCode = EXIT_CODE_ERROR
..output = 'Error running worker:\n$e\n$s';
attempt.responseCompleter.complete(response);
_cleanUp(worker);
}
});
}