The SharedJsonBuffer returns proxy objects that point into shared memory. When recv() releases the slot (via slotsAvailable.release()), a producer can immediately overwrite that memory. If the consumer hasn't finished reading the value yet, it gets corrupted and ownKeys can return duplicates, and property reads return undefined.
One fix would be to copy the value out of shared memory before releasing the slot.
But I have mixed feelings about JSON.parse(JSON.stringify(val)).
--- a/src/lib/sync/mpmc.ts
+++ b/src/lib/sync/mpmc.ts
@@ recv()
+ const copied = JSON.parse(JSON.stringify(val));
this.internals.slotsAvailable[INTERNAL_SEMAPHORE_CONTROLLER].release(1);
- return { ok: true, value: val };
+ return { ok: true, value: copied };
@@ blockingRecv()
+ const copied = JSON.parse(JSON.stringify(val));
this.internals.slotsAvailable[INTERNAL_SEMAPHORE_CONTROLLER].release(1);
- return { ok: true, value: val };
+ return { ok: true, value: copied };
The
SharedJsonBufferreturns proxy objects that point into shared memory. Whenrecv()releases the slot (viaslotsAvailable.release()), a producer can immediately overwrite that memory. If the consumer hasn't finished reading the value yet, it gets corrupted andownKeyscan return duplicates, and property reads returnundefined.One fix would be to copy the value out of shared memory before releasing the slot.
But I have mixed feelings about
JSON.parse(JSON.stringify(val)).