socket_dist_controller: sends can block the controller and hide a dead peer

Open
#2,424 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
3-5 days
Newbie friendliness
47/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
erlang

Research direction

Start with libs/estdlib/src/socket_dist_controller.erl, especially the tick handler and send_data_loop, and trace how the controller stores pending data and handles socket notifications. Check OTP distribution's nowait send behavior for context. Done means sends no longer block the controller, pending data resumes on write notification, and a blocked send beyond the tick timeout fails the connection.

Written by the indexing model from the issue text.

Description

socket_dist_controller (libs/estdlib/src/socket_dist_controller.erl) sends with socket:send/2 from the tick handler and from send_data_loop.

Since #2345, socket:send/2 waits for the socket to be writable again when the send buffer is full. If the peer stops reading (a hung node, a dead link not yet detected by TCP), the controller gen_server blocks in socket:send/2. It also stops handling tick, which is what should detect a dead peer.

OTP's distribution uses nowait sends for this reason: the controller keeps running, and the sender is notified when the socket can be written.

Possible direction: send with a nowait variant (or socket:nif_send/2 and nif_select_write/2 directly) from the controller, keep the unsent rest in the state, resume from the write notification, and treat a blocked send that lasts longer than the tick timeout as a failed connection.

Raised by @bettio in the review of #2345, where a follow-up issue was agreed.

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.