Skip to content

Let CancelledError propagate from async execute - #3010

Merged
janiversen merged 1 commit into
pymodbus-dev:devfrom
ChrisJr404:cancel-propagate
Aug 27, 2026
Merged

Let CancelledError propagate from async execute#3010
janiversen merged 1 commit into
pymodbus-dev:devfrom
ChrisJr404:cancel-propagate

Conversation

@ChrisJr404

Copy link
Copy Markdown
Contributor

Fixes #3009.

The async execute path caught asyncio.CancelledError and re-raised it as a ModbusIOException. Because that is a plain Exception, callers using a try/except Exception around read/write calls swallow it, so Task.cancel() no longer actually cancels a request that is waiting for a response.

Dropping the handler lets the CancelledError propagate normally, which releases the lock on the way out and cancels the task as expected. Updated the cancel scenario in the transaction test to check the task is cancelled rather than expecting the wrapped exception.

@janiversen janiversen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, thanks

@janiversen
janiversen merged commit 4789354 into pymodbus-dev:dev Aug 27, 2026
16 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.

Task.cancel() can't cancel async clients, TransactionManager.execute swallows CancelledError

2 participants