Skip to content

sockets: ordering of send() vs. poll() when using socket API + DTLS causes a crash #13380

@mike-scott

Description

@mike-scott

Describe the bug
Using current in-tree LwM2M client sample (samples/net/lwm2m_client) with overlay-dtls.conf, results in a crash due to how TLS handshake is implemented in the socket APIs.

For UDP, the TLS handshake is initiated during the first send(), for TCP it's started at connect(). In the LwM2M engine the socket is added to a poll() loop after connect() and this seems to be what is causing the crash. If I re-order the addition of the socket to the poll() loop to after the first send(), the crash goes away (such as https://github.com/foundriesio/zephyr/commit/9004322201131cf873e00611a9ddd2e3f38088e9)

To Reproduce
Steps to reproduce the behavior:

  1. (in another window) setup net-tools for qemu
  2. (in another window) start local Leshan (LwM2M server)
  3. cd samples/net/lwm2m_client
  4. mkdir build; cd build
  5. cmake -DBOARD=qemu_x86 -DOVERLAY_CONFIG=overlay-dtls.conf
  6. make run

Expected behavior
Expect to be able to add the socket to the poll() loop prior to send() and not have a crash in the LwM2M engine.

Impact
This behavior seems incorrect atm. It's a complexity, if the developer needs to know not to poll() on a socket until the first send() (for UDP).

Environment (please complete the following information):

  • OS: Arch Linux
  • Zephyr SDK
  • Master branch @ d2886ab

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions