Skip to content

Commit 662c91c

Browse files
committed
fix Messages stuck in queue when write fails on replaced channel
1 parent 5caed35 commit 662c91c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,16 @@ export async function initNetwork(
805805
// Re-fetch queue in case cleanupStalePeers deleted it during the await
806806
const currentQueue = getMessageQueue(targetPeerId);
807807
currentQueue.enqueue(message);
808+
809+
// If a new channel is active (stale channel was replaced by inbound connection),
810+
// flush the queue on it to prevent messages from being stuck indefinitely
811+
const newChannel = channels.get(targetPeerId);
812+
if (newChannel && newChannel !== channel) {
813+
logger.log(
814+
`${targetPeerId}:: stale channel replaced, flushing queue on new channel`,
815+
);
816+
await flushQueuedMessages(targetPeerId, newChannel, currentQueue);
817+
}
808818
}
809819
}
810820

0 commit comments

Comments
 (0)