Title: inspector: abort (no message) when the main thread posts to an exiting Worker's connectToMainThread() session · Issue #67079 · nodejs/node · GitHub
Open Graph Title: inspector: abort (no message) when the main thread posts to an exiting Worker's connectToMainThread() session · Issue #67079 · nodejs/node
X Title: inspector: abort (no message) when the main thread posts to an exiting Worker's connectToMainThread() session · Issue #67079 · nodejs/node
Description: Version v24.21.0, v24.22.1. src/inspector/main_thread_interface.cc is unchanged through v26.12.1 and main (ec7a28f). Platform Linux x64 (Ubuntu 24.04), official nodejs.org binaries Subsystem inspector, worker What steps will reproduce th...
Open Graph Description: Version v24.21.0, v24.22.1. src/inspector/main_thread_interface.cc is unchanged through v26.12.1 and main (ec7a28f). Platform Linux x64 (Ubuntu 24.04), official nodejs.org binaries Subsystem inspec...
X Description: Version v24.21.0, v24.22.1. src/inspector/main_thread_interface.cc is unchanged through v26.12.1 and main (ec7a28f). Platform Linux x64 (Ubuntu 24.04), official nodejs.org binaries Subsystem inspec...
Opengraph URL: https://github.com/nodejs/node/issues/67079
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"inspector: abort (no message) when the main thread posts to an exiting Worker's connectToMainThread() session","articleBody":"### Version\n\nv24.21.0, v24.22.1. `src/inspector/main_thread_interface.cc` is unchanged through v26.12.1 and `main` (ec7a28f2).\n\n### Platform\n\nLinux x64 (Ubuntu 24.04), official nodejs.org binaries\n\n### Subsystem\n\ninspector, worker\n\n### What steps will reproduce the bug?\n\nA 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()`.\n\n[`test/parallel/test-inspector-connect-to-main-thread.js`](https://github.com/nodejs/node/blob/ec7a28f2e074f0ea16ecd4d2a3511b334fa4b0de/test/parallel/test-inspector-connect-to-main-thread.js#L16-L19) is the minimal form: connect, disconnect, exit.\n\n### How often does it reproduce? Is there a required condition?\n\nRarely. 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.\n\nRequired 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.\n\n### What is the expected behavior? Why is that the expected behavior?\n\nNo 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](https://github.com/nodejs/node/blob/ec7a28f2e074f0ea16ecd4d2a3511b334fa4b0de/src/inspector/main_thread_interface.cc#L317-L323)), and `~AnotherThreadObjectReference` posts unconditionally, noting \"Disappearing thread may cause a memory leak\" ([#L101-L104](https://github.com/nodejs/node/blob/ec7a28f2e074f0ea16ecd4d2a3511b334fa4b0de/src/inspector/main_thread_interface.cc#L101-L104)). The test above says \"Do not crash\".\n\n### What do you see instead?\n\nSIGABRT, with no Node error message. Main thread, v24.21.0 (gdb on the core):\n\n```text\n#2 abort ()\n#3 node::inspector::MainThreadInterface::Post(...) [clone .cold]\n#4 node::inspector::(anonymous namespace)::ThreadSafeDelegate::SendMessageToFrontend(...)\n#5 node::inspector::(anonymous namespace)::ChannelImpl::sendResponse(...)\n...\n#8 v8_inspector::protocol::Debugger::DomainDispatcherImpl::pause(...)\n...\n#14 node::inspector::MainThreadInterface::DispatchMessages() [clone .part.0]\n```\n\nThe Worker's thread at the same moment:\n\n```text\n#2 uv_mutex_lock\n#3 node::inspector::MainThreadInterface::~MainThreadInterface()\n#4 std::_Sp_counted_base\u003c...>::_M_release_last_use_cold()\n#5 node::inspector::NodeInspectorClient::~NodeInspectorClient()\n...\n#7 node::Environment::~Environment()\n#9 node::FreeEnvironment(node::Environment*)\n#10 node::worker::Worker::Run()\n```\n\nOn 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`.\n\n### Additional information\n\nCause, at ec7a28f2:\n\n- `MainThreadHandle::Post` holds `block_lock_` and forwards only while `main_thread_` is set ([L317-L323](https://github.com/nodejs/node/blob/ec7a28f2e074f0ea16ecd4d2a3511b334fa4b0de/src/inspector/main_thread_interface.cc#L317-L323)). `main_thread_` is cleared only by `~MainThreadInterface` ([L202-L205](https://github.com/nodejs/node/blob/ec7a28f2e074f0ea16ecd4d2a3511b334fa4b0de/src/inspector/main_thread_interface.cc#L202-L205)), which runs after the interface's only long-lived owner, `NodeInspectorClient::interface_` ([inspector_agent.cc#L840](https://github.com/nodejs/node/blob/ec7a28f2e074f0ea16ecd4d2a3511b334fa4b0de/src/inspector_agent.cc#L840)), has dropped the use count to zero.\n- In that window, `MainThreadInterface::Post` calls `shared_from_this()` when its queue is empty ([L213](https://github.com/nodejs/node/blob/ec7a28f2e074f0ea16ecd4d2a3511b334fa4b0de/src/inspector/main_thread_interface.cc#L213)). Node builds with `-fno-exceptions` ([common.gypi#L605](https://github.com/nodejs/node/blob/ec7a28f2e074f0ea16ecd4d2a3511b334fa4b0de/common.gypi#L605)), so the expired `shared_from_this()` aborts instead of throwing `std::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 two `bad_weak_ptr` branches, and the captured return address is `0x7812c5`. The Worker above is waiting in `Reset()` for `block_lock_`, which the main thread holds.\n- `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 after `disconnect()`, as the test does, can hit this.\n\nEvery 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.\n\nDisclosure: 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.\n","author":{"url":"https://github.com/nick-inkeep","@type":"Person","name":"nick-inkeep"},"datePublished":"2026-10-28T08:44:34Z","url":"https://github.com/nodejs/node/issues/67079"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d020c579-2ae3-0fe8-f0b1-09191b82c22b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 801E:FBBFE:743779:96DCD5:6B06288A |
| html-safe-nonce | c61b167906ee53036c7a7b87ffbe557cb29339ffbead3334d413b4fb086e46ab |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MDFFOkZCQkZFOjc0Mzc3OTo5NkRDRDU6NkIwNjI4OEEiLCJ2aXNpdG9yX2lkIjoiMTE1OTgxMzA1NjMwNjc1MTYyNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 874c5f8f4a0798c0f4535836fbeb8b492b5855e62acee83ece7b00985b95b119 |
| hovercard-subject-tag | issue:6075557690 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/67079/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cd7a5128d955994bd954d135f2c295d59045ee397e237d2160c0568c7fdb0be6/nodejs/node/issues/67079 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cd7a5128d955994bd954d135f2c295d59045ee397e237d2160c0568c7fdb0be6/nodejs/node/issues/67079 |
| og:image:alt | Version v24.21.0, v24.22.1. src/inspector/main_thread_interface.cc is unchanged through v26.12.1 and main (ec7a28f). Platform Linux x64 (Ubuntu 24.04), official nodejs.org binaries Subsystem inspec... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nick-inkeep |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9e10bb0ecc0bd0f8692aa89586ee9b54e498d7ab9f244a44cdb5b93653a125ce |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 32e57d5cc2ce6ce92ec6dceb65858344750c27c2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width