nodejs / nodejs/node

EALREADY when reconnecting socket after destroying immediately after connecting

オープン
#55,519 コメント 11 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

net
主要言語
JavaScript
スター
122k
フォーク
37.3k
平均マージ
4日 2時間
マージ済み PR(30日)
283

説明

Version

v22.10.0

Platform
Darwin xxx.local 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:21 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T8103 arm64
Subsystem

No response

What steps will reproduce the bug?
import { Socket } from 'node:net';

const socket = new Socket();
socket.on('error', (err) => {
  console.log(err);
});
socket.on('connect', () => {
  console.log('connected');
});
socket.connect({ host: 'google.com', port: 80 });
socket.once('close', () => {
  console.log('closed');
  socket.connect({ host: 'google.com', port: 80 });
});
socket.destroy();
How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

Seeing

closed
connected

in the console.

What do you see instead?
closed
Error: connect EALREADY 142.250.179.174:2404 - Local (192.168.178.178:61323)
    at internalConnect (node:net:1097:16)
    at defaultTriggerAsyncIdScope (node:internal/async_hooks:464:18)
    at GetAddrInfoReqWrap.emitLookup [as callback] (node:net:1496:9)
    at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:132:8) {
  errno: -37,
  code: 'EALREADY',
  syscall: 'connect',
  address: '142.250.179.174',
  port: 2404
}
Additional information

Calling socket.destroySoon(); or socket.end(); does work as intended, but IMO socket.destroy(); should also allow a reconnect immediately afterwards. Note that calling socket.destroy(); on a socket that has been connected does allow for immediate reconnect afterwards as expected.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、報告されたプラットフォーム上で提供された node:net Socket の例を再現し、次に Socket の connect/destroy ライフサイクルと、スタックトレースで示された internalConnect パスを追跡します。destroy() の直後の再接続が EALREADY なしで connected に到達し、すでに接続されている場合の destroy-and-reconnect の動作が維持されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, node.js
領域
networking
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
55/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。