Skip to content

Commit 8fd731c

Browse files
authored
fix(orchestration): subscribeToTransfers() atomically (#10553)
refs: #10391 ## Description There was a race in subscribeToTransfers. Use a `Vow` to avoid the race. ### Security / Scaling / Upgrade / Documentation Considerations can't think of any ### Testing Considerations I'm not sure how to make a test for this. The purpose of this fix is mostly to stop other tests from failing.
2 parents 5b09631 + 7b77993 commit 8fd731c

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

packages/orchestration/src/exos/packet-tools.js

+8-12
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export const preparePacketTools = (zone, vowTools) => {
126126
const resolverToPattern = zone.detached().mapStore('resolverToPattern');
127127
return {
128128
lca,
129-
reg: /** @type {Remote<TargetRegistration> | null} */ (null),
129+
reg: /** @type {Vow<TargetRegistration> | null} */ (null),
130130
resolverToPattern,
131131
upcallQueue: /** @type {any[] | null} */ (null),
132132
pending: 0,
@@ -327,23 +327,19 @@ export const preparePacketTools = (zone, vowTools) => {
327327
}
328328
this.state.pending = 0;
329329
this.state.upcallQueue = null;
330-
// FIXME when it returns undefined this causes an error:
331-
// In "unsubscribeFromTransfers" method of (PacketToolsKit utils): result: undefined "[undefined]" - Must be a promise
332330
return watch(this.facets.utils.unsubscribeFromTransfers());
333331
},
334332
subscribeToTransfers() {
335333
// Subscribe to the transfers for this account.
336-
const { lca, reg } = this.state;
337-
if (reg) {
338-
return when(reg);
334+
const { lca, reg: cachedReg } = this.state;
335+
if (cachedReg) {
336+
return when(cachedReg);
339337
}
338+
// Atomically update the registration.
340339
const { tap } = this.facets;
341-
// XXX racy; fails if subscribeToTransfers is called while this promise is in flight
342-
// e.g. 'Target "agoric1fakeLCAAddress" already registered'
343-
return when(E(lca).monitorTransfers(tap), r => {
344-
this.state.reg = r;
345-
return r;
346-
});
340+
const reg = watch(E(lca).monitorTransfers(tap));
341+
this.state.reg = reg;
342+
return when(reg);
347343
},
348344
unsubscribeFromTransfers() {
349345
const { reg, monitor } = this.state;

0 commit comments

Comments
 (0)