Skip to content

Commit

Permalink
fix: properly abort all communication when CapTP is disconnected
Browse files Browse the repository at this point in the history
This rejects promises with the abort exception.
  • Loading branch information
michaelfig committed Jul 29, 2020
1 parent 4bd78e9 commit c2c0196
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
10 changes: 8 additions & 2 deletions packages/captp/lib/captp.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ import { isPromise } from '@agoric/produce-promise';

export { E, HandledPromise, Nat };

export function makeCapTP(ourId, send, bootstrapObj = undefined) {
export function makeCapTP(ourId, rawSend, bootstrapObj = undefined) {
let unplug = false;
function send(...args) {
if (unplug) {
throw unplug;
}
return rawSend(...args);
}

// convertValToSlot and convertSlotToVal both perform side effects,
// populating the c-lists (imports/exports/questions/answers) upon
Expand Down Expand Up @@ -253,14 +259,14 @@ export function makeCapTP(ourId, send, bootstrapObj = undefined) {
// Pull the plug!
CTP_ABORT(obj) {
const { exception } = obj;
unplug = true;
for (const pr of questions.values()) {
pr.rej(exception);
}
for (const pr of imports.values()) {
pr.rej(exception);
}
send(obj);
unplug = exception;
},
};

Expand Down
8 changes: 8 additions & 0 deletions packages/captp/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import harden from '@agoric/harden';
import Nat from '@agoric/nat';

export * from '@agoric/eventual-send';
export * from '@agoric/marshal';

export * from './captp';
export { harden, Nat };
3 changes: 2 additions & 1 deletion packages/cosmic-swingset/lib/ag-solo/vats/captp.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// in its own makeHardener, etc.
import { makeCapTP } from '@agoric/captp/lib/captp';

export const getCapTPHandler = (E, send, getBootstrapObject) => {
export const getCapTPHandler = (send, getBootstrapObject, powers) => {
const chans = new Map();
const handler = harden({
onOpen(_obj, meta) {
Expand All @@ -17,6 +17,7 @@ export const getCapTPHandler = (E, send, getBootstrapObject) => {
origin,
sendObj,
getBootstrapObject,
{ harden, ...powers },
);
chans.set(channelHandle, [dispatch, abort]);
},
Expand Down
6 changes: 4 additions & 2 deletions packages/cosmic-swingset/lib/ag-solo/vats/vat-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ export function buildRootObject(vatPowers) {

// Assign the captp handler.
// TODO: Break this out into a separate vat.
const captpHandler = getCapTPHandler(E, send, () =>
const captpHandler = getCapTPHandler(
send,
// Harden only our exported objects.
harden(exportedToCapTP),
() => harden(exportedToCapTP),
{ E, harden, ...vatPowers },
);
registerURLHandler(captpHandler, '/private/captp');
}
Expand Down

0 comments on commit c2c0196

Please sign in to comment.