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

未关闭 适合新手
#2,476 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
erlang
领域
backend

调研方向

阅读 libs/avm_network/src/epmd.erl,重点查看 process_req/3 中处理 ?PORT_PLEASE2_REQ 和 ?NAMES_REQ 的分支,并将它们的发送处理方式与 #2345 修改的 ALIVE2 分支进行比较。确认发送失败如何处理,以及服务器会保留已注册的节点;完成标准是任一响应发送失败都不会导致 epmd gen_server 崩溃。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Erlang
星标
2.3k
派生
171
平均合并
4 天 11 小时
30 天内合并 PR
20

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

atomvm/AtomVM 的其他 Issue

查看 atomvm/AtomVM 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。