openstenoproject/plover

Unplugging a serial-over-USB steno machine leaves Plover in an undefined state

Closed this issue · 0 comments

sol commented

Description

When you unplug a serial-over-USB steno machine then:

  • The thread that handles the serial connection dies silently.
  • Other parts of the system never learn about this.
  • The tray icon is never updated, the disconnect is never indicated to the user.

Steps to reproduce

  1. Plug a GeminiPR serial-over-USB machine into a free USB port of your computer (e.g. a USB keyboard running QMK).
  2. In Plover, configure and connect the machine.
  3. Unplug the machine from your computer.

Expected behavior

Tray icon and mouseover text should indicate that the machine is disconnected:

expected

Actual behavior

Tray icon and mouse overtext wrongly indicate that the machine is connected:

actual

Operating system

  • OS: Linux 5.19.4 (zen patches)
  • Plover Version: 3066a9a (master)

Discussion

Plover handles serial connections in a dedicated machine thread. The machine thread communicates events to other parts of the system via callbacks.

When you unplug a serial-over-USB device then pyserial indicates the disconnect by throwing an exception:

serial.serialutil.SerialException: device reports readiness to read but returned no data
(device disconnected or multiple access on port?)

Plover does not handle these exceptions. Instead the machine thread dies silently.

This has been discussed before in #596 and more recently in #1273. There is also a related PR that address the issue #1054.

From what I can tell, this is straightforward to fix. I’m not sure what exactly is holding a fix back. Two things I noticed:

  1. Reading through all the related discussions gets unwieldy quickly. To address this I hope that this issue provides a more compact summary.
  2. The exciting PR is technically a breaking change. To address this I opened #1560, an alternative approach that does not introduce any breaking changes.