Skip to content

Commit 96830ca

Browse files
michaelfigdckc
authored andcommitted
fix: subscribeToTransfers atomically
1 parent 6d3e14f commit 96830ca

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

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

+8-10
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,
@@ -331,17 +331,15 @@ export const preparePacketTools = (zone, vowTools) => {
331331
},
332332
subscribeToTransfers() {
333333
// Subscribe to the transfers for this account.
334-
const { lca, reg } = this.state;
335-
if (reg) {
336-
return when(reg);
334+
const { lca, reg: cachedReg } = this.state;
335+
if (cachedReg) {
336+
return when(cachedReg);
337337
}
338+
// Atomically update the registration.
338339
const { tap } = this.facets;
339-
// XXX racy; fails if subscribeToTransfers is called while this promise is in flight
340-
// e.g. 'Target "agoric1fakeLCAAddress" already registered'
341-
return when(E(lca).monitorTransfers(tap), r => {
342-
this.state.reg = r;
343-
return r;
344-
});
340+
const reg = watch(E(lca).monitorTransfers(tap));
341+
this.state.reg = reg;
342+
return when(reg);
345343
},
346344
unsubscribeFromTransfers() {
347345
const { reg, monitor } = this.state;

0 commit comments

Comments
 (0)