lwIP sockets: a peer reset does not wake processes blocked in socket:send/2 or recv

Open
#2,432 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
1-2 days
Newbie friendliness
57/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c, embedded-iot, erlang

Research direction

Read tcp_err_cb in src/libAtomVM/otp_socket.c, then compare its connected-socket handling with socket:close/1 and send_closed_notification. Check how the read and write selecting flags and their owners are handled, keeping in mind lwIP has already freed the pcb when this callback runs. Done means a peer reset wakes processes blocked in send/2 or recv, with no pcb function called after the reset.

Written by the indexing model from the issue text.

Description

On platforms using lwIP (rp2), tcp_err_cb in src/libAtomVM/otp_socket.c only answers a process trapped in socket:connect/2. For a connected socket it resets socket_state to SocketStateTCPConnected, which drops the SocketStateSelectingRead/SocketStateSelectingWrite flags, and nobody is notified.

Since #2345, socket:send/2 waits for write-readiness with nif_select_write/2 when the send buffer is full. If the peer sends a RST while a process is blocked there (or blocked in recv), the process stays blocked forever. A later socket:close/1 cannot abort it either, because the selecting flag was cleared.

Possible direction: in tcp_err_cb, for a connected socket, notify the owner of each selected direction (as socket:close/1 does with send_closed_notification) and keep the flags consistent, instead of resetting the state. Note that lwIP has already freed the pcb when tcp_err_cb runs, so tcp_pcb must be set to NULL and no pcb function may be called.

This was listed as a known limitation in #2345 and raised by @bettio in the review, where a follow-up issue was requested. Related: #2424.

Dominant language
Erlang
Stars
2.3k
Forks
171
Avg merge
4d 11h
Merged PRs (30d)
20

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from atomvm/AtomVM

All issues in atomvm/AtomVM

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.