Skip to content

fix(cie): update checkout action and fix cancel_executor race#52

Merged
atsushi421 merged 2 commits intomainfrom
fix/ci-and-cancel-executor-race
Apr 22, 2026
Merged

fix(cie): update checkout action and fix cancel_executor race#52
atsushi421 merged 2 commits intomainfrom
fix/ci-and-cancel-executor-race

Conversation

@atsushi421
Copy link
Copy Markdown
Collaborator

@atsushi421 atsushi421 commented Apr 22, 2026

Description

Fix two issues found during repository-wide code review:

  1. CI: Update actions/checkout versionrun-pre-commit.yaml was using actions/checkout@v2 (deprecated, Node.js 12-based) while build-and-test.yaml already uses @v4. Updated to @v4 for consistency and security.

  2. Fix race condition in cancel_executor — The thread_initialized flag was set to true before spin() internally sets spinning=true. If cancel_executor observed thread_initialized==true and skipped the is_spinning() wait, it could call cancel() (which sets spinning=false) before spin() set spinning=true. The subsequent spin() would override the cancellation and run indefinitely, blocking thread.join() forever.

    The fix:

    • Remove the thread_initialized fast-path and always wait for is_spinning() before calling cancel().
    • Remove the thread_initialized field from ExecutorWrapper entirely.
    • Add a joinable() guard to avoid undefined behavior if the thread was never started (e.g., std::thread constructor threw).
    • Add an explanatory comment documenting why the unconditional is_spinning() wait is necessary, to prevent re-introduction of the fast-path optimization.

Related links

How was this PR tested?

Notes for reviewers

- Update actions/checkout from v2 to v4 in run-pre-commit workflow
  for consistency with build-and-test workflow and security.
- Fix race condition in cancel_executor where thread_initialized could
  be true before spin() sets spinning=true, causing cancel() to have
  no effect. Always wait for is_spinning() before cancelling.

Signed-off-by: atsushi421 <atsushi.yano.2@tier4.jp>
- Add comment explaining why cancel_executor must always wait for
  is_spinning() to prevent re-introduction of the race condition.
- Add joinable() guard to avoid undefined behavior when the thread
  was never started.

Signed-off-by: atsushi421 <atsushi.yano.2@tier4.jp>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses CI hygiene and a concurrency bug that could deadlock executor shutdown.

Changes:

  • Updated run-pre-commit.yaml to use actions/checkout@v4 (consistent with the repo’s other workflow and avoids deprecated Node 12-based checkout).
  • Removed the thread_initialized fast-path in cancel_executor() and now always waits for executor->is_spinning() before calling cancel(), preventing a race where cancellation could be overwritten.
  • Added a std::thread::joinable() guard to avoid joining an unstarted thread.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
callback_isolated_executor/src/component_container_callback_isolated.cpp Removes thread_initialized and fixes a shutdown race by waiting for is_spinning() before cancel + join, plus adds a joinable guard.
.github/workflows/run-pre-commit.yaml Bumps actions/checkout from v2 to v4.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@atsushi421 atsushi421 marked this pull request as ready for review April 22, 2026 21:35
@atsushi421 atsushi421 enabled auto-merge April 22, 2026 21:36
@atsushi421 atsushi421 merged commit 93a054d into main Apr 22, 2026
7 checks passed
@atsushi421 atsushi421 deleted the fix/ci-and-cancel-executor-race branch April 22, 2026 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants