Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear up uncertain await safety #6739

Merged
merged 8 commits into from
Jan 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "module",
"devDependencies": {
"@endo/eslint-config": "^0.5.1",
"@jessie.js/eslint-plugin": "^0.2.1",
"@jessie.js/eslint-plugin": "^0.3.0",
"@types/node": "^16.7.10",
"@typescript-eslint/parser": "^5.33.0",
"ava": "^5.0.1",
Expand Down Expand Up @@ -75,6 +75,7 @@
"**/espree/acorn": "^8.7.1",
"**/puppeteer-core/node-fetch": "^2.6.5",
"**/eslint/@babel/code-frame": "^7.12.11",
"**/eslint-config-react-app/eslint-plugin-jest": "^26.0.0"
"**/eslint-config-react-app/eslint-plugin-jest": "^26.0.0",
"**/@endo/eslint-config/@jessie.js/eslint-plugin": "^0.3.0"
}
}
1 change: 1 addition & 0 deletions packages/SwingSet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@endo/zip": "^0.2.28",
"anylogger": "^0.21.0",
"import-meta-resolve": "^1.1.1",
"jessie.js": "^0.3.2",
"microtime": "^3.1.0",
"semver": "^6.3.0"
},
Expand Down
48 changes: 27 additions & 21 deletions packages/SwingSet/src/vats/network/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { E } from '@endo/eventual-send';
import { Far } from '@endo/marshal';
import { makePromiseKit } from '@endo/promise-kit';
import { assert, details as X, Fail } from '@agoric/assert';
import { asyncGenerate } from 'jessie.js';
import { toBytes } from './bytes.js';

import '@agoric/store/exported.js';
Expand Down Expand Up @@ -235,18 +236,20 @@ export function makeNetworkProtocol(protocolHandler) {
*/
const bind = async localAddr => {
// Check if we are underspecified (ends in slash)
if (localAddr.endsWith(ENDPOINT_SEPARATOR)) {
for (;;) {
// eslint-disable-next-line no-await-in-loop
const portID = await E(protocolHandler).generatePortID(
localAddr,
protocolHandler,
);
const newAddr = `${localAddr}${portID}`;
if (!boundPorts.has(newAddr)) {
localAddr = newAddr;
break;
}
const underspecified = localAddr.endsWith(ENDPOINT_SEPARATOR);
const whileUnderspecified = asyncGenerate(() => ({
done: !underspecified,
value: null,
}));
for await (const _ of whileUnderspecified) {
const portID = await E(protocolHandler).generatePortID(
localAddr,
protocolHandler,
);
const newAddr = `${localAddr}${portID}`;
if (!boundPorts.has(newAddr)) {
localAddr = newAddr;
michaelfig marked this conversation as resolved.
Show resolved Hide resolved
break;
}
}

Expand Down Expand Up @@ -371,25 +374,24 @@ export function makeNetworkProtocol(protocolHandler) {
bind,
async inbound(listenAddr, remoteAddr) {
let lastFailure = Error(`No listeners for ${listenAddr}`);
for (const listenPrefix of getPrefixes(listenAddr)) {
for await (const listenPrefix of getPrefixes(listenAddr)) {
if (!listening.has(listenPrefix)) {
// eslint-disable-next-line no-continue
continue;
}
const [port, listener] = listening.get(listenPrefix);
let localAddr;
try {
await (async () => {
// See if our protocol is willing to receive this connection.
// eslint-disable-next-line no-await-in-loop
const localInstance = await E(protocolHandler)
.onInstantiate(port, listenPrefix, remoteAddr, protocolHandler)
.catch(rethrowUnlessMissing);
localAddr = localInstance
? `${listenAddr}/${localInstance}`
: listenAddr;
} catch (e) {
})().catch(e => {
michaelfig marked this conversation as resolved.
Show resolved Hide resolved
lastFailure = e;
// eslint-disable-next-line no-continue
});
if (!localAddr) {
continue;
}
// We have a legitimate inbound attempt.
Expand Down Expand Up @@ -459,15 +461,19 @@ export function makeNetworkProtocol(protocolHandler) {
: localAddr;

let lastFailure;
try {
let accepted;
await (async () => {
// Attempt the loopback connection.
const attempt = await protocolImpl.inbound(
remoteAddr,
initialLocalAddr,
);
return attempt.accept({ handler: lchandler });
} catch (e) {
accepted = await attempt.accept({ handler: lchandler });
})().catch(e => {
lastFailure = e;
});
if (accepted) {
return accepted;
}

const {
Expand Down
1 change: 1 addition & 0 deletions packages/agoric-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"deterministic-json": "^1.0.5",
"esm": "agoric-labs/esm#Agoric-built",
"inquirer": "^8.2.2",
"jessie.js": "^0.3.2",
"opener": "^1.5.2",
"tmp": "^0.2.1",
"ws": "^7.2.0"
Expand Down
8 changes: 3 additions & 5 deletions packages/agoric-cli/src/cosmos.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,9 @@ export default async function cosmosMain(progname, rawArgs, powers, opts) {
);
}

if (popts.pull) {
const exitStatus = await pspawn('docker', ['pull', IMAGE]);
if (exitStatus) {
return exitStatus;
}
const exitStatus = await (popts.pull && pspawn('docker', ['pull', IMAGE]));
if (exitStatus) {
return exitStatus;
}

return helper(rawArgs.slice(1));
Expand Down
Loading