inspector: abort (no message) when the main thread posts to an exiting Worker's connectToMainThread() session
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript
調査の方向性
Start with src/inspector/main_thread_interface.cc, especially MainThreadHandle::Post, MainThreadInterface::Post, and the destructor that resets the handle; read NodeInspectorClient ownership in inspector_agent.cc as well. Run test/parallel/test-inspector-connect-to-main-thread.js and inspect its connect, disconnect, and exit sequence. Done means posts racing with Worker shutdown are tolerated without aborting.
索引モデルが issue の本文から書いたものです。
説明
Version
v24.21.0, v24.22.1. src/inspector/main_thread_interface.cc is unchanged through v26.12.1 and main (ec7a28f2).
Platform
Linux x64 (Ubuntu 24.04), official nodejs.org binaries
Subsystem
inspector, worker
What steps will reproduce the bug?
A Worker opens new inspector.Session().connectToMainThread() and exits while the main thread still has something to post back to that session: a protocol reply or event, or the delete it sends when the main-thread side of the session is destroyed after session.disconnect().
test/parallel/test-inspector-connect-to-main-thread.js is the minimal form: connect, disconnect, exit.
How often does it reproduce? Is there a required condition?
Rarely. It needs a narrow native interleaving, and there is no deterministic JS reproduction. Seen twice in CI, in a suite that repeatedly connects, pauses and disconnects Worker sessions to the main thread. Node's CI has seen the test above crash with exit code -6 and no output (#54804, closed as a duplicate of #40611). With no native stack there, I can't confirm it is this bug.
Required condition: the main thread posts to the Worker's handle, while the Worker's request queue is empty, after the Worker's MainThreadInterface use count reaches zero and before ~MainThreadInterface resets the handle.
What is the expected behavior? Why is that the expected behavior?
No crash. Posting to a thread that is going away is meant to be tolerated: MainThreadHandle::Post returns false once the handle is reset (main_thread_interface.cc#L317-L323), and ~AnotherThreadObjectReference posts unconditionally, noting "Disappearing thread may cause a memory leak" (#L101-L104). The test above says "Do not crash".
What do you see instead?
SIGABRT, with no Node error message. Main thread, v24.21.0 (gdb on the core):
#2 abort ()
#3 node::inspector::MainThreadInterface::Post(...) [clone .cold]
#4 node::inspector::(anonymous namespace)::ThreadSafeDelegate::SendMessageToFrontend(...)
#5 node::inspector::(anonymous namespace)::ChannelImpl::sendResponse(...)
...
#8 v8_inspector::protocol::Debugger::DomainDispatcherImpl::pause(...)
...
#14 node::inspector::MainThreadInterface::DispatchMessages() [clone .part.0]
The Worker's thread at the same moment:
#2 uv_mutex_lock
#3 node::inspector::MainThreadInterface::~MainThreadInterface()
#4 std::_Sp_counted_base<...>::_M_release_last_use_cold()
#5 node::inspector::NodeInspectorClient::~NodeInspectorClient()
...
#7 node::Environment::~Environment()
#9 node::FreeEnvironment(node::Environment*)
#10 node::worker::Worker::Run()
On v24.22.1 the Worker's thread is the same, and the main thread's post comes from the session's deletion instead: MainThreadInterface::RemoveObject → ~SameThreadInspectorSession → ~ChannelImpl → ~ThreadSafeDelegate → MainThreadInterface::Post [clone .cold] → abort.
Additional information
Cause, at ec7a28f2:
MainThreadHandle::Postholdsblock_lock_and forwards only whilemain_thread_is set (L317-L323).main_thread_is cleared only by~MainThreadInterface(L202-L205), which runs after the interface's only long-lived owner,NodeInspectorClient::interface_(inspector_agent.cc#L840), has dropped the use count to zero.- In that window,
MainThreadInterface::Postcallsshared_from_this()when its queue is empty (L213). Node builds with-fno-exceptions(common.gypi#L605), so the expiredshared_from_this()aborts instead of throwingstd::bad_weak_ptr. In the official v24.21.0 linux-x64 binary,Post's cold block (0x7812c0:call abort@plt) is reached only from that call's twobad_weak_ptrbranches, and the captured return address is0x7812c5. The Worker above is waiting inReset()forblock_lock_, which the main thread holds. disconnect()returns once the delete is queued on the main thread (the delegate is "destroyed asynchronously", #46942), and nothing tells the Worker when the main thread is done with the session. A Worker that exits right afterdisconnect(), as the test does, can hit this.
Every cross-thread post to a Worker's interface goes through these two functions, so a fix there covers the reply, event and delete paths. Fix idea: reset the handle while the interface is still owned, for example in ~NodeInspectorClient before interface_ is released, so a racing post takes the existing return false path. Using weak_from_this() at L213 would also remove the abort.
Disclosure: this report was drafted and posted by an AI coding agent (Claude Code) at the direction of @nick-inkeep, who decided to file it. Before posting, a second, independent agent re-checked every linked source line at ec7a28f2, the duplicate searches, both stacks (symbol-mapped against the official v24.21.0 and v24.22.1 linux-x64 binaries) and the disassembly.
- 主要言語
- JavaScript
- スター
- 123k
- フォーク
- 39.3k
- 平均マージ
- 4日 15時間
- マージ済み PR(30日)
- 238
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
nodejs/node のほかの issue
-
util: parseArgs() treats a `-` inside a short option group as the `--` terminator対応中かも @yohannesjoya が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
http2: content-encoding is incorrectly listed in kSingleValueHeaders対応中かも @inoway46 が 2 日前に担当しました。 オープンconfirmed-bug http2
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
nodejs/node#67151 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
util.parseEnv and --env-file keep a leading UTF-8 BOM in the first key対応中かも @helmipradita が 4 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
node:internal/inspector/network_http: `TypeError: Missing dataLength` in event when response uses `setEncoding()`再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
nodejs/node#66551 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Docs] `process.loadEnvFile()` does not document behaviour when variables already exist対応中かも @Sepandard が 38 日前に担当しました。 オープンdoc
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
riverqueue/river#1576 ·
メンテナーはふだん 1 日以内に返信
-
documentation good first issue
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
good first issue help wanted
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
modrollstudio/Modroll-Studio-Website#80 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
mafzalkalwardev/mailforge#21 ·
-
good first issue help wanted
難易度 1/5 1時間未満 初心者へのやさしさ 82/100