epmd: a client that closes early crashes the server on the PORT_PLEASE2 and NAMES responses

Open Beginner friendly
#2,476 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
erlang
Domain
backend

Research direction

Read libs/avm_network/src/epmd.erl, focusing on process_req/3 branches for ?PORT_PLEASE2_REQ and ?NAMES_REQ, and compare their send handling with the ALIVE2 branch changed by #2345. Confirm how send failures are handled and that the server keeps its registered nodes; done means either response can fail to send without crashing the epmd gen_server.

Written by the indexing model from the issue text.

Description

Affected: release-0.7 at ca1583068, libs/avm_network/src/epmd.erl,
process_req/3 for ?PORT_PLEASE2_REQ and ?NAMES_REQ.
#2345 fixes the same problem for the ALIVE2 response only.

What happens

The responses are sent with ok = socket:send(Socket, ...).

When the client has already closed the connection, socket:send/2 does not
return ok (on release-0.7 it returns {ok, Data} for a closed connection,
with #2345 it returns {error, closed} or {error, epipe}). The badmatch
crashes the epmd gen_server, and every registered node is forgotten.

How to reproduce

Start the epmd, then from any client:

{ok, S} = socket:open(inet, stream, tcp),
ok = socket:setopt(S, {socket, linger}, #{onoff => true, linger => 0}),
ok = socket:connect(S, #{family => inet, addr => loopback, port => 4369}),
ok = socket:send(S, <<2:16, 122, "x">>),   % PORT_PLEASE2_REQ for node "x"
ok = socket:close(S).                       % reset, no reply is read

The server's reply fails and the epmd process crashes. The race is easiest to
hit with a slow server, for example under valgrind.

Suggested fix

Handle {error, _} like the ALIVE2 branch does after #2345: close the socket
and keep the state.

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.