Skip to content

Commit

Permalink
rpctransport/tty: Fix TypeError when TTY client is closed
Browse files Browse the repository at this point in the history
The executor that reads the serial port is not terminated gracefully by
aioserial when close is called and thus it touches some variables set to
`Note` at that point causing `TypeError` to be raised. We handle this as
disconnect because it should happen only on disconnect.

The fix seems to be present in PR
mrjohannchang/aioserial.py#7 but it seems that
development of this project somewhat stalled. We should think about
moving to some alternative if nothing happens in year or two.
  • Loading branch information
Cynerd committed Jan 22, 2025
1 parent 2c02d6d commit e832301
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Close of TTY client causing `TypeError` to be raised in receive task


## [0.7.3] - 2024-10-31
### Fixed
- Invalid unpack of date and time from ChainPack for dates before 2018-02-02
Expand Down
5 changes: 4 additions & 1 deletion shv/rpctransport/tty.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ async def _read_exactly(self, n: int) -> bytes:
while len(res) < n:
try:
res += await self.serial.read_async(n - len(res))
except aioserial.SerialException as exc:
# Note: TypeError is raised because serial.close() clears some
# variables that are still used in the task. This is bug in
# aioserial.
except (aioserial.SerialException, TypeError) as exc:
self._eof.set()
raise EOFError from exc
return res
Expand Down

0 comments on commit e832301

Please sign in to comment.