ssl:recv/2 has no timeout (no ssl:recv/3)

Open
#2,434 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
55/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
erlang
Domain
networking

Research direction

Start in libs/estdlib/src/ssl.erl at ssl:recv/2 and its want_read select notification handling; compare the timeout behavior in AtomVM's gen_tcp or socket APIs and OTP's ssl:recv/3. Done means recv/3 accepts a timeout, recv/2 behaves as an infinite-timeout call, and a timed-out receive cancels its select and returns {error, timeout}.

Written by the indexing model from the issue text.

Description

ssl:recv/2 (libs/estdlib/src/ssl.erl) waits on want_read with a bare receive for the select notification:

receive
    {'$socket', Socket, select, Ref} -> recv0(...);
    {'$socket', Socket, abort, {Ref, closed}} -> {error, closed}
end

If the peer stops sending but the TCP connection isn't closed (NAT drop, cellular link stall, a server that stops mid-stream), the call never returns. OTP has ssl:recv/3 with a Timeout, and gen_tcp/socket in AtomVM already accept timeouts, but ssl exports only recv/2.

We hit this on ESP32 downloading firmware over HTTPS through a 4G modem: the stream stalled and the process sat in ssl:recv/2 until we added an external watchdog that kills it.

Proposal: add recv/3 with Timeout :: timeout() (recv/2 = recv(S, L, infinity)), with an after clause that cancels the select (socket:nif_select_stop/1 or equivalent) and returns {error, timeout}, as OTP does. Happy to send a PR.

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 Networking issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.