Skip to content

Commit 5caed35

Browse files
committed
fixing race condition
1 parent e45f9a0 commit 5caed35

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

packages/ocap-kernel/src/remotes/network.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,16 @@ export async function initNetwork(
391391
continue;
392392
}
393393

394+
// Check if peer was intentionally closed during dial
395+
if (intentionallyClosed.has(peerId)) {
396+
logger.log(
397+
`${peerId}:: peer intentionally closed during dial, closing channel`,
398+
);
399+
await connectionFactory.closeChannel(channel, peerId);
400+
reconnectionManager.stopReconnection(peerId);
401+
return;
402+
}
403+
394404
// Register the new channel and start reading
395405
registerChannel(peerId, channel);
396406
}
@@ -762,6 +772,15 @@ export async function initNetwork(
762772
return;
763773
}
764774

775+
// Check if peer was intentionally closed during dial
776+
if (intentionallyClosed.has(targetPeerId)) {
777+
logger.log(
778+
`${targetPeerId}:: peer intentionally closed during dial, closing channel`,
779+
);
780+
await connectionFactory.closeChannel(channel, targetPeerId);
781+
throw new Error('Message delivery failed after intentional close');
782+
}
783+
765784
// Register the new channel and start reading
766785
registerChannel(targetPeerId, channel);
767786
}

0 commit comments

Comments
 (0)