Close USB serial port off the UI isolate

close(2) on a tty whose output the peer never drained blocks in the
kernel for the line discipline's closing_wait (measured 30.4s on Linux
against a CDC-ACM device that never reads its bulk OUT endpoint, e.g. a
MeshCore board flashed with a BLE-only companion build). FlSerial's
closePort() is a synchronous FFI call, so the whole app froze for that
window on every failed USB connect and on disconnect.

fl_close() only touches process-global native state, so run it through
Isolate.run() and replicate the Dart-side cleanup closePort() does
(stream close, calloc'd I/O buffers, flh reset). Log when the close
exceeds 1s so the "device is not draining" case is visible in the debug
log.

Verified against the wedged device: inline close blocked the calling
isolate for 30476ms with 0 timer ticks; the isolate close took 30302ms
with 302 ticks, i.e. the main isolate stayed responsive throughout.
This commit is contained in:
Gianluca Boiano committed 2026-09-13 12:30:51 +02:00
1 parent 92e1d15d1c
commit 4a25f718a8
2 files changed
+55 -1

No files matched your search

+1
View File
@@ -43,6 +43,7 @@ dependencies:
git:
url: https://github.com/MeshEnvy/flserial.git
ref: 48216310061efc8d5d217cc18014fc2cb501646e
ffi: ^2.1.3 # calloc.free for flserial's native I/O buffers
provider: ^6.1.5+1
shared_preferences: ^2.2.2
uuid: ^4.3.3