Skip to content

fix: share ThreadSafeBus send lock with default periodic tasks - #2116

Merged
zariiii9003 merged 2 commits into
hardbyte:mainfrom
timothyanderson096-ocdealcheck:fix/thread-safe-periodic-1620
Nov 26, 2026
Merged

zariiii9003 merged 2 commits into
hardbyte:mainfrom
timothyanderson096-ocdealcheck:fix/thread-safe-periodic-1620

Conversation

@timothyanderson096-ocdealcheck

Copy link
Copy Markdown
Contributor

Summary of Changes

Default thread-based periodic tasks call the wrapped backend directly, bypassing ThreadSafeBus.send. The null periodic context therefore permits a manual send and a periodic send, or two periodic workers, to enter backend.send concurrently.

Assign the wrapper's reentrant send lock to the backend's default periodic-task lock after initializing the send/receive locks. Preserve direct backend dispatch and separate receive locking. Add two event-controlled behavioral regressions with real VirtualBus delivery, a clarifying docstring sentence and a news fragment.

Related Issues / Pull Requests

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactoring
  • Other

Checklist

  • I have followed the contribution guide.
  • I have added or updated tests as appropriate.
  • I have added or updated documentation as appropriate.
  • I have added a news fragment for towncrier.
  • All checks and tests pass (tox).

Additional Notes

Validation recorded on 25 October 2026, Linux / CPython 3.13.16:

  • Both new tests fail on original production code with maximum simultaneous backend sends 2, versus expected 1.
  • Candidate plus existing simplecyclic suite: 9 passed, including an independent rerun.
  • Positive Event barriers establish that the contender reached the actual attempted lock acquisition or the incorrectly unlocked backend before releasing the first send. Tests check backend overlap and actual VirtualBus payloads, then join workers before shutdown.
  • Configured tox lint, type and docs environments pass. The five mypy targets (3.10–3.14) are static checks, not five executed runtimes.
  • Configured full suite: 505 passed, 29 subtests passed, 98 skipped and 28 failures; unchanged base: 503 passed, 98 skipped and the same 28 failure identities. All failures are multicast IPv4/IPv6 interface initialization in that environment (errno 19). The suite remains failing and the all-checks checkbox remains unchecked.
  • Checkout and installed tox module bytes were matched to the pinned source for thread_safe_bus, bus, broadcastmanager and virtual. No assertions or skips were weakened.

On 27 October, public head 4fdc38364c97b79828983059d9985cd316eb714c was recovered with full tree 62abe5d4dcdaa2cebcc413648a789b7212b54f2d, exactly matching tested clean candidate 97c97b4 on unchanged main b4f82ab. The saved raw tests, installed-source identities and equal full-suite failure sets were inspected again; Python/tox checks were not rerun during this publication refresh.

The contract is mutual exclusion for default thread-based periodic sends, not bounded backend latency or synchronous cancellation. Independent inspection reproduced the same existing non-joining stop/post-shutdown-send limitation on base and candidate. A blocking backend send can retain the shared lock. Native/specialized periodic implementations, physical hardware and the full OS/interpreter CI matrix remain unvalidated.

Prepared with AI assistance and independently inspected during the original preparation.

Timothy Anderson — Spotted Ridge Engineering / OC Labs
Independent software verification · GDN (Global Decision Network)
timothyanderson096@gmail.com · Engineering evidence

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-28T00:29:01.720851Z
We couldn’t complete this review. Comment @codex review to try again.
4fdc383 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@timothyanderson096-ocdealcheck

Copy link
Copy Markdown
Contributor Author

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@zariiii9003

Copy link
Copy Markdown
Collaborator

AI Review: share ThreadSafeBus send lock with default periodic tasks

The fix in can/thread_safe_bus.py is correct and minimal: it addresses #1620 for every bus that uses the default ThreadBasedCyclicSendTask, including the SocketCAN and IXXAT fallbacks. Both new tests fail on main and pass with the fix. The changes requested concern the tests only.

Tests

  • test/test_thread_safe_periodic.py is a new file. test/simplecyclic_test.py already holds the ThreadSafeBus.send_periodic tests. Please move the test there and delete the new file.
  • The test depends on an internal name. It patches can.thread_safe_bus.RLock to see when the second sender tries to take the lock. Any change to how ThreadSafeBus creates its lock would break the test, even with correct behaviour. Please drop ObservedRLock, contender_id and mark_contender. Instead, while the first send is blocked, assert assertFalse(second_entered.wait(0.1)); then release it and assert assertTrue(second_entered.wait(5)).
  • There is more test code than the fix needs.
    • Keep only test_manual_and_periodic_send_do_not_overlap. It already catches every plausible regression the periodic/periodic case would catch, because both depend on the same shared lock.
    • Remove the final recv() payload check. Message delivery through VirtualBus and periodic sending are already covered in simplecyclic_test.py.

Verdict

request changes

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I've addressed the test feedback in faf6e82: the single regression is now in test/simplecyclic_test.py, uses events at the backend send boundary rather than patching RLock, and reuses the existing thread-joining helper. The separate test file, periodic/periodic case and payload assertions have been removed. The production fix and changelog are unchanged.

I checked the revised test in an isolated lock-behaviour harness (20/20 expected failures with the old locking behaviour, 20/20 passes with the corrected behaviour). This is not an upstream test-suite result; the revised test still needs to run against the actual package in CI.

@zariiii9003 zariiii9003 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.

thank you

@zariiii9003
zariiii9003 merged commit 5304e1b into hardbyte:main Nov 26, 2026
28 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.

2 participants