Honor manual disconnect and re-validate state after waiting
Sixth review round: - disconnect(manual: true) joining an in-flight automatic teardown now still marks it manual (and cancels the reconnect timer / stops the background service), so a user-initiated disconnect can no longer be followed by an auto-reconnect scheduled by the teardown it joined. - _shouldAutoReconnect is false once _disposed, so a teardown that outlives disposal cannot arm a timer that calls connect() on a disposed connector. - connect()/connectUsb()/connectTcp() and UsbSerialService.connect() re-check the connection state after awaiting the in-flight teardown. The await is a suspension point, so two callers could previously pass the initial guard, resume together and both run the open sequence.
This commit is contained in:
3 files changed
+54
-1
No files matched your search
@@ -144,6 +144,13 @@ class UsbSerialService {
|
||||
} catch (_) {
|
||||
// Failures are already logged by the teardown path.
|
||||
}
|
||||
|
||||
// The await above is a suspension point: another caller may have claimed
|
||||
// the transport while this one waited.
|
||||
if (_status == UsbSerialStatus.connected ||
|
||||
_status == UsbSerialStatus.connecting) {
|
||||
throw StateError('USB serial transport is already active');
|
||||
}
|
||||
}
|
||||
|
||||
_status = UsbSerialStatus.connecting;
|
||||
|
||||
Reference in new issue
Block a user