lwIP sockets: socket:close/1 does not release the processes selecting on the socket
メンテナーはふだん 3 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 76/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- c, erlang
調査の方向性
src/libAtomVM/otp_socket.cを読み、nif_socket_closeのOTP_SOCKET_LWIP分岐に注目してください。提案されているクリーンアップを、socket_stopのBSD経路と比較してください。読み取りと書き込みの両方の選択について、socket_select_disownとref_ticksがどのように扱われるかを確認してください。lwIPソケットを閉じると、選択中のプロセスが解放され、それらのプロセスが生存したままリソースデストラクタが実行されるようになれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Affected: release-0.7 at ca1583068, lwIP socket backend (RP2 port; ESP32 uses BSD sockets).
Not fixed by #2345 (c4a2824f4), which extends the problem to the write direction.
What happens
On BSD sockets, socket:close/1 stops the select event and the stop callback
demonitors the selecting process, so the resource can be freed.
On lwIP, nif_socket_close only sends the closed notification. The selecting
process stays registered as owner: its pid, its monitor and the reference the
monitor holds on the resource are never released.
The socket resource (struct, rwlock, unread pbufs in received_list) is therefore
kept alive until the owning process exits, or selects again on that same socket.
A long-lived process that opens, uses and closes many sockets leaks one resource
per connection for its whole lifetime. With #2345, a process that waited for write
readiness in socket:send/2 leaks the same way.
How to reproduce (Pico W)
In one process, loop:
{ok, S} = socket:open(inet, stream, tcp),
ok = socket:connect(S, Peer),
{ok, _} = socket:recv(S, 0, 1000), % arms a read select: this process becomes owner
ok = socket:close(S)
Add a trace to socket_dtor: it does not run while the process lives.
Free heap shrinks on every iteration.
Where
src/libAtomVM/otp_socket.c, nif_socket_close, #elif OTP_SOCKET_LWIP branch.
Suggested fix
After sending the closed notifications, disown both directions
(socket_select_disown on read_select and write_select, reset their
ref_ticks), as socket_stop does on BSD sockets.
- 主要言語
- Erlang
- スター
- 2.3k
- フォーク
- 171
- 平均マージ
- 4日 11時間
- マージ済み PR(30日)
- 20
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
atomvm/AtomVM のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 3 日以内に返信
-
lwIP sockets: a failed listen or connect leaves the socket lock held, a later close hangs foreverオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
メンテナーはふだん 3 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
config ⚙
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
micropython/micropython#19942 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100