Skip to content
This repository was archived by the owner on Nov 1, 2024. It is now read-only.

Commit 8619b92

Browse files
authored
Fix bug around handling of failures in spawnWorker calls (#87)
Fixes #86 If a worker process fails to spawn, we will now complete the work attempt that caused the process to spawn with that failure, instead of never completing the attempt at all, causing a hang, and also leaking the async exception as an unhandled exception. We could add retry logic in the future if we want, but it is probably unlikely that trying again will work. This way the actual failure should be reliably surfaced though.
1 parent 372b8b5 commit 8619b92

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.1.1
2+
3+
* Fix a bug where if spawnWorker threw an error, work requests would hang
4+
forever instead of failing.
5+
16
## 1.1.0
27

38
* Add constructors with named parameters to

lib/src/driver/driver.dart

+4
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ class BazelWorkerDriver {
120120
_readyWorkers.remove(worker);
121121
_runWorkQueue();
122122
});
123+
}).onError<Object>((e, s) {
124+
_spawningWorkers.remove(futureWorker);
125+
if (attempt.responseCompleter.isCompleted) return;
126+
attempt.responseCompleter.completeError(e, s);
123127
});
124128
}
125129
// Recursively calls itself until one of the bail out conditions are met.

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: bazel_worker
2-
version: 1.1.0
2+
version: 1.1.1
33
description: >-
44
Protocol and utilities to implement or invoke persistent bazel workers.
55
repository: https://github.com/dart-lang/bazel_worker

test/driver_test.dart

+6
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ void main() {
139139
});
140140
});
141141

142+
test('handles spawnWorker failures', () async {
143+
driver = BazelWorkerDriver(() async => throw StateError('oh no!'),
144+
maxRetries: 0);
145+
expect(driver!.doWork(WorkRequest()), throwsA(isA<StateError>()));
146+
});
147+
142148
tearDown(() async {
143149
await driver?.terminateWorkers();
144150
expect(MockWorker.liveWorkers, isEmpty);

0 commit comments

Comments
 (0)