Skip to content

Commit 3a460c2

Browse files
committed
Refactor AndroidEnvelopeSender start method to ensure proper closure handling during worker spawning. Introduce a guard clause to close the worker if the sender is already closed, enhancing stability and preventing resource leaks.
1 parent 05ce8b7 commit 3a460c2

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

packages/flutter/lib/src/native/java/android_envelope_sender.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ class AndroidEnvelopeSender {
3434
FutureOr<void> start() async {
3535
if (_isClosed) return;
3636
if (_worker != null) return;
37-
_worker = await _spawn(_config, _entryPoint);
37+
final worker = await _spawn(_config, _entryPoint);
38+
// Guard against close() being called during spawn.
39+
if (_isClosed) {
40+
worker.close();
41+
return;
42+
}
43+
_worker = worker;
3844
}
3945

4046
FutureOr<void> close() {

0 commit comments

Comments
 (0)