Skip to content

BlockDownloadStream class in sdo\client.py appears to be missing an object definition #624

Open

Description

@Eqqm4n

Hello-
In sdo\client.py the BlockDownloadStream class refers to the self.crc_supported attribute on lines 680, 738, and 812, but this class attribute does not appear to be defined (and as a side note, the BlockUploadStream class does define one).

I ran across this issue when a host's block transfer request was rejected by the device, causing the library to go down one of these broken code paths:

2026-01-05 14:42:37,387 - canopen_client - ERROR - Full traceback:
Traceback (most recent call last):
  File "C:\nVent_work\zephyr_root\zephyr_repo\nvent_projects\canopen_sim\canopen_sim\canopen_client.py", line 724, in upload_firmware
    with self.node.sdo.open(index, subindex, "wb",
         ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
                          size=total_size,
                          ^^^^^^^^^^^^^^^^
                          block_transfer=True) as fp:
                          ^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python313\Lib\site-packages\canopen\sdo\client.py", line 213, in open
    raw_stream = BlockDownloadStream(self, index, subindex, size, request_crc_support=request_crc_support)
  File "C:\Program Files\Python313\Lib\site-packages\canopen\sdo\client.py", line 655, in __init__
    response = sdo_client.request_response(request)
  File "C:\Program Files\Python313\Lib\site-packages\canopen\sdo\client.py", line 86, in request_response
    return self.read_response()
           ~~~~~~~~~~~~~~~~~~^^
  File "C:\Program Files\Python313\Lib\site-packages\canopen\sdo\client.py", line 74, in read_response
    raise SdoAbortedError(abort_code)
canopen.sdo.exceptions.SdoAbortedError: Code 0x05040001, Unknown SDO command specified
2026-01-05 14:42:37,391 - canopen_client - ERROR - Error uploading firmware: Code 0x05040001, Unknown SDO command specified
Exception ignored in: <canopen.sdo.client.BlockDownloadStream object at 0x000001F2DDEF6A40>
Traceback (most recent call last):
  File "C:\Program Files\Python313\Lib\site-packages\canopen\sdo\client.py", line 793, in close
    if self.crc_supported:
AttributeError: 'BlockDownloadStream' object has no attribute 'crc_supported'
2026-01-05 14:42:38,548 - canopen_client - INFO - Disconnected from CAN bus

Activity

  1. acolomb commented on Apr 29, 2026

    @acolomb
    Member

    Not sure where the second exception really comes from. Anyway, the class attribute crc_supported should be superfluous, as the constructor initializes the instance attribute. If it fails early because of an exception, then there is no object to call .close() on. So how did that call end up in your log's second traceback anyway?

  2. Eqqm4n commented on May 1, 2026

    @Eqqm4n
    Author

    Hello- based on what you're saying, then it seems like the constructor is not correctly setting this property. As can be seen in the code snippet at the top of the log, any time I attempt a block transfer code execution branches down that path where it should have been defined.

  3. dhairyajangir commented on Nov 10, 2026

    @dhairyajangir

    A virtual CAN replay reproduced both exceptions on the parent of #590. The peer rejects the initial block-download request with 0x05040001. Python then finalizes the partially initialized raw stream and calls close(), which reads crc_supported before the constructor has set it.

    The same exchange on v2.4.1 raises only the expected SdoAbortedError. The initialization guard from #590 is included in v2.4.0 and v2.4.1. The replay covered Python 3.12 and 3.14.

    AI assisted with the reproduction and this note.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions