Skip to content

Commit

Permalink
fix: don't create new promise IDs and stall the pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed May 25, 2021
1 parent d5e0272 commit b596232
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/captp/lib/captp.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,21 @@ export function makeCapTP(ourId, rawSend, bootstrapObj = undefined, opts = {}) {
// eslint-disable-next-line no-use-before-define
const pr = makeRemoteKit(questionID);
questions.set(questionID, pr);

// To fix #2846:
// We return 'p' to the handler, and the eventual resolution of 'p' will
// be used to resolve the caller's Promise, but the caller never sees 'p'
// itself. The caller got back their Promise before the handler ever got
// invoked, and thus before queueMessage was called. If that caller
// passes the Promise they received as argument or return value, we want
// it to serialize as resultVPID. And if someone passes resultVPID to
// them, we want the user-level code to get back that Promise, not 'p'.
lastPromiseID += 1;
const promiseID = lastPromiseID;
const resultVPID = `p+${promiseID}`;
valToSlot.set(pr.p, resultVPID);
slotToVal.set(resultVPID, pr.p);

return [questionID, pr];
}

Expand Down

0 comments on commit b596232

Please sign in to comment.