emcy: Fix maximum timeout logic errors in EmcyConsumer.wait() by acolomb · Pull Request #668 · canopen-python/canopen · GitHub
Skip to content

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

Open
acolomb wants to merge 3 commits into
canopen-python:masterfrom
acolomb:fix-emcy-wait-timeout
Open

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

Conversation

@acolomb

@acolomb acolomb commented May 26, 2026

Copy link
Copy Markdown
Member

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

codecov Bot commented May 26, 2026

Copy link
Copy Markdown

@acolomb

acolomb commented May 26, 2026

Copy link
Copy Markdown
Member Author

@acolomb acolomb added the bug label Jun 14, 2026
@acolomb acolomb marked this pull request as ready for review June 29, 2026 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant