Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: setTimeout causes process hangs #10

Merged
merged 2 commits into from
Aug 21, 2023

Conversation

AriPerkkio
Copy link
Contributor

@AriPerkkio AriPerkkio commented Aug 20, 2023

Description

Fixes process hangs when birpc is run inside child_process.

  • unref() the setTimeout calls. Conditionally for browser support.
  • Clear timeout IDs once promise is resolved - no need to create unnecessary Error's and call reject for every single rpc call

Linked Issues

Fixes #9

Additional context

Related to vitest-dev/vitest#3925

reject(new Error(`[birpc] timeout on calling "${method}"`))
rpcPromiseMap.delete(id)
}, timeout)
}, timeout).unref?.()
Copy link
Owner

Choose a reason for hiding this comment

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

.unref might need to be called conditionally as birpc will also run on browsers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

setTimeout should always return something in browsers. Isn't condition for unref? enough?

https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#return_value

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, true

@antfu antfu merged commit 4e168fb into antfu:main Aug 21, 2023
2 checks passed
@AriPerkkio AriPerkkio deleted the fix/set-timeout-process-hang branch August 21, 2023 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

setTimeout can cause process hangs when run in node:child_process
2 participants