Skip to content

Auto-reconnect USB boards and fix reconnect crash (3.3.1) - #24

Merged
awhitchurch merged 3 commits into
mainfrom
usb-reconnect
Nov 3, 2026
Merged

awhitchurch merged 3 commits into
mainfrom
usb-reconnect

Conversation

@awhitchurch

Copy link
Copy Markdown
Contributor

Summary

Makes USB sessions survive a board reset or replug, and fixes the crash that happened when reconnecting after an abrupt unplug. Also bumps the version to 3.3.1+137 for release.

Crash fix and link-loss handling

  • Fixes a double free in sp_free_config: SerialPort.dispose() already frees the config, so disposing it ourselves aborted the app on the next disconnect.
  • If the reader errors or closes, the port is torn down immediately and a new TransportStatus.lost is reported.
  • shutdown() is now single-flight, so a link-loss teardown and a user disconnect can't dispose the port twice.

Auto-reconnect

  • On a lost link, ConnectionController keeps the session (descriptor, buffers, packet listeners), so an active recording continues.
  • It polls for the port by name, or by USB serial number if the OS renamed it. Once the port is back, it waits 1.2 s for the bootloader, resets the framer and reopens the port.
  • It gives up after 30 s. A link that drops again within 5 s of a reconnect counts as the same outage.
  • The Live view stays up with a "reconnecting" banner and Cancel button, and the Home card shows the reconnecting state.
  • A new desktop-only setting, "Reconnect automatically", is on by default.

Testing

  • flutter test: all 42 tests pass. None of them cover the reconnect path, as this PR adds no tests.
  • flutter analyze: 11 info-level lints, no errors or warnings.

🤖 Generated with Claude Code

awhitchurch and others added 3 commits October 15, 2026 19:03
The SerialPort.config setter caches the config and SerialPort.dispose()
frees it, so disposing it ourselves after assignment double-freed it in
sp_free_config on the next disconnect. That aborted the app when
reconnecting after an abrupt unplug.

Also handle the reader erroring or closing: tear the port down
immediately and report a new TransportStatus.lost. shutdown() is now
single-flight so a link-loss teardown and a user disconnect can't
dispose the port twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the USB transport reports a lost link, ConnectionController keeps
the session (descriptor, buffers, packet listeners, so an active
recording continues) and polls for the port to come back: by the same
name, or by USB serial number if the OS renamed it. Once present it waits
1.2 s for the bootloader to hand over, resets the framer and reopens the
port. It gives up after 30 s; a link that drops again within 5 s of a
reconnect counts toward the same outage.

The Live view stays up with a "reconnecting" banner and Cancel button,
and the Home card shows the reconnecting state. A desktop-only setting
("Reconnect automatically", on by default) turns the feature off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@awhitchurch
awhitchurch merged commit b625e49 into main Nov 3, 2026
1 check passed
@awhitchurch
awhitchurch deleted the usb-reconnect branch November 3, 2026 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant