Skip to content

fix(canopen): stop a block download's sub-block batch when the transfer ends - #259

Merged
dborgards merged 1 commit into
mainfrom
fix/canopen-block-download-abort
Oct 2, 2026
Merged

dborgards merged 1 commit into
mainfrom
fix/canopen-block-download-abort

Conversation

@dborgards

Copy link
Copy Markdown
Owner

What does this change?

Fixes finding C9 of the 2026-09-30 deep review: a block download sent its sub-block as one ordered batch that nothing could stop. After a server abort or a cancel the rest of the segments still went out, and a server without a session reads them as command specifiers, in the worst case as expedited writes into its dictionary. The batch now checks before each frame whether the transfer's task is complete.

Type of change

  • feat — new behaviour (minor release)
  • fix / perf — bug or performance fix (patch release)
  • docs / test / refactor / chore / ci — no release
  • Breaking change (! in the title, plus a BREAKING CHANGE: footer explaining the migration)

Checklist

  • dotnet build CanKit.Pro.sln -c Release succeeds (with -p:CI=true)
  • dotnet test CanKit.Pro.sln -c Release passes (net10.0, --no-build)
  • Public API changes are documented with XML comments — none
  • New behaviour is covered by a test — both endings (server abort, cancel); fails with the check disabled
  • The requirement or ADR this relates to is referenced — FR-CO-004

Also run: dotnet format --verify-no-changes, dotnet pack + eng/verify-packages.py.

Notes

  • The no-more-segments assertion has a 300 ms negative window (nothing signals "nothing more is coming"); it can only pass falsely on a slow host, never fail falsely.
  • Not changed: the block-upload server's batch, whose peer is a client that ignores stray segments.

🤖 Generated with Claude Code

…er ends

SendNextBlockDownloadSubBlock sends up to 127 segments as one ordered batch with no way to
stop it. When the server aborted, the caller cancelled or the transfer ended otherwise
while the batch was still going, only the client session was removed and the remaining
segments were sent anyway. The server has no block session then and reads each segment as
a command specifier: a seqno of 0x20..0x3F is a classic download initiate, and 0x23, 0x27,
0x2B and 0x2F are expedited writes that land in the dictionary when the bytes that
happen to be the multiplexer name a writable object of that width.

The batch now asks before each frame whether the transfer's task is complete, which every
way of ending it sets and which is readable from the sending task. The upload server's
batch is not touched; its peer is a client that ignores stray segments.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@cursor

cursor Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches CANopen SDO block TX ordering on a background send path; behavior change is narrow (stop stray segments) but wire-protocol mistakes could affect remote object dictionaries.

Overview
Fixes a case where block download still transmitted the rest of a sub-block after the transfer had already finished (peer abort, caller cancel, timeout, or dispose). Those frames could hit a server with no session and be parsed as SDO command specifiers.

SendOrderedControlFrames now accepts an optional shouldStop predicate, evaluated on the send task before each frame. Block download passes session.Tcs.Task.IsCompleted so the ordered segment batch exits once the transfer task has completed.

A new test covers server abort and caller cancel mid sub-block (first segment held on deferred echo) and asserts no further segments are transmitted.

Reviewed by Cursor Bugbot for commit c0bdff5. Bugbot is set up for automated code reviews on this repo. Configure here.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 2, 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 ✅ Completed 2026-10-02T04:03:00.214231Z c0bdff5 PR opened
ℹ️ 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.

@codecov

codecov Bot commented Oct 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@dborgards
dborgards merged commit 0a0b507 into main Oct 2, 2026
21 of 22 checks passed
@dborgards
dborgards deleted the fix/canopen-block-download-abort branch October 2, 2026 04:19
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