Add retry writing to DevFS. (#8142)

This is a workaround to #8141
This commit is contained in:
Todd Volkert 2017-02-14 09:59:43 -08:00 committed by GitHub
parent 43650e93f4
commit f903a1c841

View File

@ -222,6 +222,7 @@ class _DevFSHttpWriter {
final Uri httpAddress;
static const int kMaxInFlight = 6;
static const int kMaxRetries = 3;
int _inFlight = 0;
Map<String, DevFSContent> _outstanding;
@ -256,9 +257,12 @@ class _DevFSHttpWriter {
}
}
Future<Null> _scheduleWrite(String devicePath,
DevFSContent content,
DevFSProgressReporter progressReporter) async {
Future<Null> _scheduleWrite(
String devicePath,
DevFSContent content,
DevFSProgressReporter progressReporter, [
int retry = 0,
]) async {
try {
HttpClientRequest request = await _client.putUrl(httpAddress);
request.headers.removeAll(HttpHeaders.ACCEPT_ENCODING);
@ -270,7 +274,13 @@ class _DevFSHttpWriter {
HttpClientResponse response = await request.close();
await response.drain<Null>();
} catch (e) {
printError('Error writing "$devicePath" to DevFS: $e');
if (retry < kMaxRetries) {
printTrace('Retrying writing "$devicePath" to DevFS due to error: $e');
_scheduleWrite(devicePath, content, progressReporter, retry + 1);
return;
} else {
printError('Error writing "$devicePath" to DevFS: $e');
}
}
if (progressReporter != null) {
_done++;