chrysn / aiocoap

The Python CoAP library
Other
262 stars 119 forks source link

Invalid payload size on BERT transport #301

Closed ChrisCuts closed 1 year ago

ChrisCuts commented 1 year ago

We got an exception thrown by the client migrating the server to version 0.4.5:

<ERROR> asyncio - Task exception was never retrieved
future: <Task finished name='Task-4' coro=<CoapClient.get_content() done, defined at /workspace/src/coap_client.py:240> exception=NetworkError('None')>
Traceback (most recent call last):
  File "/workspace/src/coap_client.py", line 248, in get_content
    resp = await self.get('/events')
  File "/workspace/src/coap_client.py", line 113, in get
    response = await self._send(path)
  File "/workspace/src/coap_client.py", line 68, in _send
    return await self._context.request(request).response
  File "/usr/local/lib/python3.8/site-packages/aiocoap/protocol.py", line 842, in _run_outer
    await cls._run(app_request, response, weak_observation, protocol, log)
  File "/usr/local/lib/python3.8/site-packages/aiocoap/protocol.py", line 894, in _run
    blockresponse = await blockrequest.response
aiocoap.error.NetworkError: None

After some research it figured out, that the payload is not divisible with 1024, what is necessary for BERT messages. grafik

There seems to be a floor operation problem in the message.py _extract_block method. Please see PR https://github.com/chrysn/aiocoap/pull/299 for more information.

ChrisCuts commented 1 year ago

It was introduced in 0.4.4 due to the additional slack in rfc8323common.py maximum_payload_size

Patch for 0.4.4 and 0.4.5

from aiocoap.message import Message

_extract_block = Message._extract_block
Message._extract_block = \
    lambda s, n, szs, max_szs: _extract_block(s, n, szs, 1024 * (max_szs // 1024))
chrysn commented 1 year ago

Thanks for the report and providing the fix!

ChrisCuts commented 1 year ago

Glad to.

Is there a release planned in near future?

chrysn commented 1 year ago

Yes, I'd just like to get a few other changes (eg. updating Group OSCORE) in for the release. So far, it doesn't look like I've racked up anything too breaking, so it'll be a minor release.

chrysn commented 1 year ago

Release 0.4.7 is out and contains these changes.