Skip to content

emcy: Fix maximum timeout logic errors in EmcyConsumer.wait()#668

Draft
acolomb wants to merge 1 commit into
canopen-python:masterfrom
acolomb:fix-emcy-wait-timeout
Draft

emcy: Fix maximum timeout logic errors in EmcyConsumer.wait()#668
acolomb wants to merge 1 commit into
canopen-python:masterfrom
acolomb:fix-emcy-wait-timeout

Conversation

@acolomb
Copy link
Copy Markdown
Member

@acolomb acolomb commented May 26, 2026

If an EMCY package was received, but filtered out by the emcy_code matching, the condition waiting is started again with the same timeout. Thus the actual maximum waiting time is not correctly limited to the given argument, as the docstring promises. Track the remaining time until the initial deadline instead, as basis for the condition wait.

Further, spurious wake-ups from the condition wait on the OS level are not handled correctly. The threading.Condition docs explicitly recommend checking the shared state (number of logged entries in this case) in the while loop, because the wait() call may abort early. The current code assumes that this necessarily indicates a timeout, without checking the actually passed time again. Reorder the check against end_time in the loop to avoid this.

If an EMCY package was received, but filtered out by the emcy_code
matching, the condition waiting is started again with the same
timeout.  Thus the actual maximum waiting time is not correctly
limited to the given argument, as the docstring promises.  Track the
remaining time until the initial deadline instead, as basis for the
condition wait.

Further, spurious wake-ups from the condition wait on the OS level are
not handled correctly.  The threading.Condition docs explicitly
recommend checking the shared state (number of logged entries in this
case) in the while loop, because the wait() call may abort early.  The
current code assumes that this necessarily indicates a timeout,
without checking the actually passed time again.  Reorder the check
against end_time in the loop to avoid this.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 26, 2026

Codecov Report

❌ Patch coverage is 42.85714% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
canopen/emcy.py 42.85% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@acolomb
Copy link
Copy Markdown
Member Author

acolomb commented May 26, 2026

This was discovered while reviewing the tests in #659. Let's merge that one first to have an accurate picture of the test coverage. Will add some more specific tests regarding this failure mode subsequently.

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