GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — doc: warn against awaiting replies in module hooks by bitpshr · Pull Request #65590 · nodejs/node

Conversation

@bitpshr

@bitpshr bitpshr commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Fixes: #63085

module.register() documents that hooks can send messages back to the registering thread, and the example does exactly that. What is not documented is that a hook cannot wait for a reply. Resolution and loading are synchronous from the perspective of the thread that triggered them, so that thread is blocked until the hook settles and can never answer in the meantime. Awaiting a reply inside a resolve or load hook deadlocks both threads.

This adds a short paragraph after the messaging example saying so. The issue reporter hit this and it is not obvious from the surrounding text, which reads as though the channel is bidirectional in the usual way.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@nodejs-github-bot

nodejs-github-bot commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot added doc Issues and PRs related to Node.js documentation. module Issues and PRs related to the module subsystem. labels Aug 27, 2026
@bitpshr

bitpshr commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Hi @nodejs/loaders, keeping this on your radar. Doc only: hooks cannot await a reply from the thread that registered them, since that thread is blocked until the hook settles. Green since August.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JakobJingleheimer
JakobJingleheimer reviewed Oct 12, 2026
View reviewed changes
Comment thread doc/api/module.md Outdated
above. It must not wait for a reply while it is running: resolution and loading
are synchronous from the perspective of the thread that triggered them, so that
thread is blocked until the hook settles and cannot answer in the meantime.
Awaiting a reply inside a `resolve` or `load` hook deadlocks both threads.

@JakobJingleheimer JakobJingleheimer Oct 12, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not true: @nodejs-loaders/tsx effectively does this (it previously did use async/await before supporting both async and sync).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bitpshr bitpshr Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JakobJingleheimer I think we are talking about two different things.

I checked @nodejs-loaders/tsx and the awaiting it does is on esbuild.transform(), a promise that resolves on its own:

return transform(rawSource, { sourcefile: url, ...esbuildConfig })
  .catch((f) => handleTrasformErrors(f, url))
  .then(({ code: source, warnings }) => {

What deadlocks is narrower: awaiting a reply from the thread that registered the hook, over the message channel from the preceding example. That thread is blocked inside the resolution or load it triggered, so it cannot run a listener to answer, and both sides wait forever. That is what the reporter hit in #63085.

So hooks can absolutely be async. The only thing that cannot be awaited is a response from the registering thread. My sentence did not make that scope clear, so how about:

A hook can send messages to the thread that registered it at any time, as above. It must not block on a reply from that thread: resolution and loading are synchronous from the perspective of the thread that triggered them, so that thread is blocked until the hook settles and cannot answer in the meantime. Hooks can otherwise be fully asynchronous; it is only a reply over this message channel that cannot be awaited.

Happy to push that, or to drop it entirely if you think the distinction is too narrow to be worth documenting.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@JakobJingleheimer JakobJingleheimer Oct 12, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh. Yes, much cleaner 🙂 thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bitpshr
bitpshr requested a review from JakobJingleheimer October 12, 2026 00:35
JakobJingleheimer
JakobJingleheimer approved these changes Oct 12, 2026
View reviewed changes
@JakobJingleheimer JakobJingleheimer added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Oct 12, 2026
jsumners-nr
jsumners-nr approved these changes Oct 12, 2026
View reviewed changes
@bitpshr
doc: warn against awaiting replies in module hooks
05c5619
Awaiting a reply from the registering thread inside a resolve or load
hook deadlocks: resolution is synchronous from that thread's
perspective, so it is blocked in the request and cannot answer.

Fixes: nodejs#63085
Signed-off-by: Paul Bouchon <[email protected]>
@bitpshr
bitpshr force-pushed the doc/hooks-no-main-thread-await branch from eba7b53 to 05c5619 Compare October 14, 2026 02:07
@bitpshr

bitpshr commented Oct 14, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Hi @JakobJingleheimer @jsumners-nr, I pushed the verbiage change mentioned here, which cleared approvals. Mind reviewing this one again? Thanks in advance.

JakobJingleheimer reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JakobJingleheimer
JakobJingleheimer approved these changes Oct 16, 2026
View reviewed changes
@JakobJingleheimer JakobJingleheimer added commit-queue PRs queued for automated landing through the Commit Queue. commit-queue-squash PRs the Commit Queue should land as one squashed commit. labels Oct 16, 2026
@nodejs-github-bot
nodejs-github-bot merged commit c0c8ce8 into nodejs:main Oct 16, 2026
22 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

Landed in c0c8ce8

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Oct 16, 2026
@aduh95 aduh95 mentioned this pull request Oct 27, 2026
2026-10-28, Version 27.0.0-alpha.0.0.0 (Alpha) #67062
Merged
aduh95 pushed a commit that referenced this pull request Nov 12, 2026
@bitpshr @aduh95
doc: warn against awaiting replies in module hooks
f534a4c
Awaiting a reply from the registering thread inside a resolve or load
hook deadlocks: resolution is synchronous from that thread's
perspective, so it is blocked in the request and cannot answer.

Fixes: #63085
Signed-off-by: Paul Bouchon <[email protected]>
PR-URL: #65590
Reviewed-By: Jacob Smith <[email protected]>
@github-actions github-actions Bot mentioned this pull request Nov 20, 2026
2026-11-30, Version 26.14.0 'Lithium' (LTS) #67664
Open
gabylb pushed a commit to gabylb/node that referenced this pull request Nov 27, 2026
@bitpshr @gabylb
doc: warn against awaiting replies in module hooks
fa4cd8c
Awaiting a reply from the registering thread inside a resolve or load
hook deadlocks: resolution is synchronous from that thread's
perspective, so it is blocked in the request and cannot answer.

Fixes: nodejs#63085
Signed-off-by: Paul Bouchon <[email protected]>
PR-URL: nodejs#65590
Reviewed-By: Jacob Smith <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@JakobJingleheimer JakobJingleheimer JakobJingleheimer approved these changes
+1 more reviewer
@jsumners-nr jsumners-nr jsumners-nr approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. commit-queue-squash PRs the Commit Queue should land as one squashed commit. doc Issues and PRs related to Node.js documentation. module Issues and PRs related to the module subsystem.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Loader stalls MessagePort since v24

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@bitpshr @nodejs-github-bot @JakobJingleheimer @jsumners-nr
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.