Skip to content

Commit bb57ad2

Browse files
(chore) add hard exit clarifications
1 parent 65d42ae commit bb57ad2

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

src/commands/recv.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,29 @@ export async function run(outDir, opts, ctx = {}) {
209209
mode,
210210
appID,
211211
};
212-
// --- Silent workaround: exit cleanly before wrtc finalizers run
213-
// Close signaling so the relay doesn't hang on our socket, then bail.
214212
} catch (e) {
215213
const msg = e?.message || String(e);
216214
process.stderr.write(`\nError: ${msg}\n`);
217215
throw e;
218216
} finally {
217+
// --- Workaround: exit before `wrtc` finalizers run
218+
// Proactively close signaling so the relay doesn’t keep our socket open,
219+
// then exit. This avoids a shutdown hang caused by known issues in the
220+
// node-webrtc fork(s):
221+
// - https://github.com/WonderInventions/node-webrtc/issues/37
222+
// - https://github.com/WonderInventions/node-webrtc/issues/35
223+
//
224+
// Until these are resolved, we exit early to prevent JS/GC finalizers from
225+
// tearing down RTCPeerConnection/libwebrtc threads in a way that can stall
226+
// the event loop.
227+
//
228+
// Suggested shutdown order:
229+
// 1) await signaling.close() // stop outbound/inbound signaling
230+
// 2) await peer?.close() // close data channels/transceivers
231+
// 3) process.exit(0) // ensure a clean, bounded exit
232+
//
233+
// TODO: remove once upstream fixes land.
234+
219235
try {
220236
offSenderReady?.();
221237
} catch {}

src/commands/send.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,24 @@ export async function run(paths, opts, ctx = {}) {
251251
process.stderr.write(summary + "\n");
252252
// --- Silent workaround on success
253253
} finally {
254-
// Hard, handler-safe close sequence
254+
// --- Workaround: exit before `wrtc` finalizers run
255+
// Proactively close signaling so the relay doesn’t keep our socket open,
256+
// then exit. This avoids a shutdown hang caused by known issues in the
257+
// node-webrtc fork(s):
258+
// - https://github.com/WonderInventions/node-webrtc/issues/37
259+
// - https://github.com/WonderInventions/node-webrtc/issues/35
260+
//
261+
// Until these are resolved, we exit early to prevent JS/GC finalizers from
262+
// tearing down RTCPeerConnection/libwebrtc threads in a way that can stall
263+
// the event loop.
264+
//
265+
// Suggested shutdown order:
266+
// 1) await signaling.close() // stop outbound/inbound signaling
267+
// 2) await peer?.close() // close data channels/transceivers
268+
// 3) process.exit(0) // ensure a clean, bounded exit
269+
//
270+
// TODO: remove once upstream fixes land.
271+
255272
await closeTransport(rtc, {
256273
signal,
257274
waitForCloseMs: 0,

0 commit comments

Comments
 (0)