Skip to content

Commit

Permalink
fix(orchestration): subscribeToTransfers() atomically (#10553)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mergify[bot] authored Nov 25, 2024
2 parents 5b09631 + 7b77993 commit 8fd731c
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions packages/orchestration/src/exos/packet-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const preparePacketTools = (zone, vowTools) => {
const resolverToPattern = zone.detached().mapStore('resolverToPattern');
return {
lca,
reg: /** @type {Remote<TargetRegistration> | null} */ (null),
reg: /** @type {Vow<TargetRegistration> | null} */ (null),
resolverToPattern,
upcallQueue: /** @type {any[] | null} */ (null),
pending: 0,
Expand Down Expand Up @@ -327,23 +327,19 @@ export const preparePacketTools = (zone, vowTools) => {
}
this.state.pending = 0;
this.state.upcallQueue = null;
// FIXME when it returns undefined this causes an error:
// In "unsubscribeFromTransfers" method of (PacketToolsKit utils): result: undefined "[undefined]" - Must be a promise
return watch(this.facets.utils.unsubscribeFromTransfers());
},
subscribeToTransfers() {
// Subscribe to the transfers for this account.
const { lca, reg } = this.state;
if (reg) {
return when(reg);
const { lca, reg: cachedReg } = this.state;
if (cachedReg) {
return when(cachedReg);
}
// Atomically update the registration.
const { tap } = this.facets;
// XXX racy; fails if subscribeToTransfers is called while this promise is in flight
// e.g. 'Target "agoric1fakeLCAAddress" already registered'
return when(E(lca).monitorTransfers(tap), r => {
this.state.reg = r;
return r;
});
const reg = watch(E(lca).monitorTransfers(tap));
this.state.reg = reg;
return when(reg);
},
unsubscribeFromTransfers() {
const { reg, monitor } = this.state;
Expand Down

0 comments on commit 8fd731c

Please sign in to comment.