Skip to content

Fix "Bad file descriptor" error when closing the serial transport#390

Merged
pavel-kirienko merged 2 commits into
OpenCyphal:master-v1from
kristkis:master-v1
Jun 27, 2026
Merged

Fix "Bad file descriptor" error when closing the serial transport#390
pavel-kirienko merged 2 commits into
OpenCyphal:master-v1from
kristkis:master-v1

Conversation

@kristkis

Copy link
Copy Markdown

Closing a SerialTransport - for example pressing Ctrl-C on yakut monitor or yakut subscribe over a serial port - reliably prints an error traceback from the reader thread on macOS/POSIX, ending in:

Exception in thread Thread-1 (_reader_thread_func):
...
  File ".../pycyphal/transport/serial/_serial.py", line 455, in _reader_thread_func
    self._serial_port.close()
  File ".../serial/serialposix.py", line 533, in close
    os.close(self.fd)
OSError: [Errno 9] Bad file descriptor

To fix it, wrap the reader-thread close in try/except and ignore the error.

Reproduced on macOS, pycyphal 1.27.0, pyserial 3.5, Python 3.12, Cyphal/serial over a USB-UART adapter.

@coveralls

coveralls commented Jun 26, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 93.394%. remained the same — kristkis:master-v1 into OpenCyphal:master-v1

@pavel-kirienko pavel-kirienko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Please bump the patch version number in __init__.py

@kristkis

Copy link
Copy Markdown
Author

Bumped to 1.27.1, thanks!

@kristkis kristkis requested a review from pavel-kirienko June 27, 2026 13:43
@pavel-kirienko pavel-kirienko merged commit 9c37dad into OpenCyphal:master-v1 Jun 27, 2026
8 checks passed
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.

3 participants