You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reject(newError(`[birpc] timeout on calling "${method}"`))
rpcPromiseMap.delete(id)
},timeout)
But what's even more critical here is that these timeouts are not cleared with clearTimeout even when rpc call succees. This means that for every single rpc call, an Error object is created after 60 second timeout.
Reproduction script to be run in birpc repository - or if running as standalone, change the import path of birpc. You'll need to install why-is-node-running to see setTimeout pointed out.
$ pnpm i -D why-is-node-running
$ touch birpc-repro.mjs # Add code here
$ node birpc-repro.mjs
import{fork}from"node:child_process";import{fileURLToPath}from"node:url";import{createRequire}from"node:module";import{createBirpc}from"./dist/index.mjs";constrequire=createRequire(import.meta.url);constwhyIsNodeRunning=require("why-is-node-running");constisMain=!Boolean(process.env.CHILD_PROCESS);constfilename=fileURLToPath(import.meta.url);if(isMain){console.log("[main-process]: Running",process.pid);constsubprocess=fork(filename,{env: {CHILD_PROCESS: "true"}});subprocess.on("exit",()=>console.log("[main-process] Subprocess exited"));console.log("[main-process]: Exiting",process.pid);}else{console.log("[sub-process] Started",process.pid);letcallback;constrpc=createBirpc(undefined,{post: (data)=>callback({t: "s",r: "Hello from RPC",i: data.i}),on: (cb)=>(callback=cb),});// This will resolve quicklyconstresponse=awaitrpc.hello();console.log("[sub-process] Received",response);console.log("[sub-process] Exiting",process.pid);// If sub-process is stuck and wont gracefully exit, this will printout root causessetTimeout(()=>whyIsNodeRunning(),5_000).unref();
Output:
$ time node main.mjs
[main-process]: Running 79086
[main-process]: Exiting 79086
[sub-process] Started 79087
[sub-process] Received Hello from RPC
[sub-process] Exiting 79087
There are 3 handle(s) keeping the process running
...
# Timeout
node:internal/async_hooks:202
node:internal/async_hooks:504
node:internal/timers:164
node:internal/timers:198
file:///x/y/z/birpc/dist/index.mjs:38
file:///x/y/z/birpc/dist/index.mjs:33
file:///x/y/z/birpc/main.mjs:36
[main-process] Subprocess exited
real 1m0.113s <-- This matches with birpc's timeout
user 0m0.142s
sys 0m0.029s
After unref()'ing the setTimeout:
$ time node main.mjs
[main-process]: Running 81181
[main-process]: Exiting 81181
[sub-process] Started 81182
[sub-process] Received Hello from RPC
[sub-process] Exiting 81182
[main-process] Subprocess exited
real 0m0.104s
user 0m0.078s
sys 0m0.025s
But what's even more critical here is that these timeouts are not cleared with clearTimeout even when rpc call succees. This means that for every single RPC call, an Error object is created after 60 second timeout.
Using the minimal reproduction above and adding console.error inside setTimeout calls reveals that these errors are created for every RPC call.
setTimeout(() => {
+ console.error(`Creating error for ${method} even though it succeeded`);
reject(new Error(`[birpc] timeout on calling "${method}"`))
rpcPromiseMap.delete(id)
}, timeout)
$ time node main.mjs
[main-process]: Running 81542
[main-process]: Exiting 81542
[sub-process] Started 81543
[sub-process] Received Hello from RPC
[sub-process] Exiting 81543
Creating error for hello even though it succeeded
[main-process] Subprocess exited
Describe the bug
When
birpc
is run insidenode:child_process
, it will leave unhandledNodeJS.Timeout
handles hanging. These should be.unref()
'ed.birpc/src/index.ts
Lines 182 to 185 in 7b1fe90
But what's even more critical here is that these timeouts are not cleared with
clearTimeout
even when rpc call succees. This means that for every single rpc call, anError
object is created after 60 second timeout.Reproduction script to be run in
birpc
repository - or if running as standalone, change the import path ofbirpc
. You'll need to installwhy-is-node-running
to seesetTimeout
pointed out.$ pnpm i -D why-is-node-running $ touch birpc-repro.mjs # Add code here $ node birpc-repro.mjs
Output:
After
unref()
'ing thesetTimeout
:$ time node main.mjs [main-process]: Running 81181 [main-process]: Exiting 81181 [sub-process] Started 81182 [sub-process] Received Hello from RPC [sub-process] Exiting 81182 [main-process] Subprocess exited real 0m0.104s user 0m0.078s sys 0m0.025s
Reproduction
Reproduction script above.
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: