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

chore: resolve floating-promise warnings in kernel packages #8214

Merged
merged 6 commits into from
Aug 28, 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
2 changes: 1 addition & 1 deletion packages/SwingSet/misc-tools/extract-xs-snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ if (!vatIDToExtract) {
const { snapPos, hash } = info;
const snapshot = snapStore.loadSnapshot(vatIDToExtract);
const fn = `${vatIDToExtract}-${snapPos}-${hash}.xss`;
E.when(fs.promises.writeFile(fn, snapshot), () =>
void E.when(fs.promises.writeFile(fn, snapshot), () =>
console.log(`wrote snapshot to ${fn}`),
);
}
4 changes: 2 additions & 2 deletions packages/SwingSet/test/test-vat-timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ test('brand', async t => {
const whenNobrand = 123n;
const delayNobrand = 123n;
ts.setWakeup(whenNobrand, handler);
ts.wakeAt(whenNobrand);
ts.delay(delayNobrand);
void ts.wakeAt(whenNobrand);
void ts.delay(delayNobrand);
ts.makeRepeater(delayNobrand, delayNobrand);
ts.repeatAfter(delayNobrand, delayNobrand, handler);
ts.makeNotifier(delayNobrand, delayNobrand);
Expand Down
4 changes: 2 additions & 2 deletions packages/SwingSet/test/transcript/test-state-sync-reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ test('state-sync reload', async t => {
const { commit } = hostStorage;
const initOpts = { addComms: false, addVattp: false, addTimer: false };
await initializeSwingset(config, [], kernelStorage, initOpts);
commit();
await commit();

const { runtimeOptions } = t.context.data;
const c1 = await makeSwingsetController(kernelStorage, {}, runtimeOptions);
Expand All @@ -82,7 +82,7 @@ test('state-sync reload', async t => {
t.is(res, i);
}

commit();
await commit();
await c1.shutdown();

const exporter = makeSwingStoreExporter(dbDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ test('transcript spans', async t => {
const { commit } = hostStorage;
const initOpts = { addComms: false, addVattp: false, addTimer: false };
await initializeSwingset(config, [], kernelStorage, initOpts);
commit();
await commit();

let c;
const restart = async () => {
if (c) {
commit();
await commit();
await c.shutdown();
}
const { runtimeOptions } = t.context.data;
Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/scripts/clean-core-eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const main = async (argv, { readFile, stdout }) => {

if (isEntrypoint(import.meta.url)) {
/* global process */
farExports.E.when(
void farExports.E.when(
import('fs/promises'),
fsp =>
main([...process.argv], {
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/src/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const makeWithQueue = () => {
}
const [thunk, resolve, reject] = queue[0];
// Run the thunk in a new turn.
Promise.resolve()
void Promise.resolve()
.then(thunk)
// Resolve or reject our caller with the thunk's value.
.then(resolve, reject)
Expand Down
2 changes: 1 addition & 1 deletion packages/solo/public/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ function run() {
commands[commands.length - 1] = inp.value;
commands[commands.length] = '';
inp.value = '';
call({ type: 'doEval', number, body: command });
void call({ type: 'doEval', number, body: command });
}

function inputKeyup(ev) {
Expand Down
12 changes: 9 additions & 3 deletions packages/solo/src/captp.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export const getCapTPHandler = (send, getLocalBootstrap, fallback) => {
dispatch,
abort,
});
doFallback('onOpen', obj, meta);
doFallback('onOpen', obj, meta).catch(e => {
console.error(`Error in fallback onOpen`, e);
});
},
onClose(obj, meta) {
console.debug(`Finishing CapTP`, meta);
Expand All @@ -53,7 +55,9 @@ export const getCapTPHandler = (send, getLocalBootstrap, fallback) => {
abort();
}
chans.delete(meta.channelHandle);
doFallback('onClose', obj, meta);
doFallback('onClose', obj, meta).catch(e => {
console.error(`Error in fallback onClose`, e);
});
},
onError(obj, meta) {
console.debug(`Error in CapTP`, meta, obj.error);
Expand All @@ -62,7 +66,9 @@ export const getCapTPHandler = (send, getLocalBootstrap, fallback) => {
const { abort } = chan;
abort(obj.error);
}
doFallback('onError', obj, meta);
doFallback('onError', obj, meta).catch(e => {
console.error(`Error in fallback onError`, e);
});
},
async onMessage(obj, meta) {
console.debug('processing inbound', obj);
Expand Down
27 changes: 16 additions & 11 deletions packages/solo/src/chain-cosmos-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export async function connectToChain(
*/
const getMailboxNotifier = () => {
const { notifier, updater } = makeNotifierKit();
retryRpcHref(async rpcHref => {
void retryRpcHref(async rpcHref => {
// Every time we enter this function, we are establishing a
// new websocket to a potentially different RPC server.
//
Expand Down Expand Up @@ -486,7 +486,7 @@ export async function connectToChain(

waitForTxHash = subscribeAndWaitForTxHash;
if (postponedTxHash) {
subscribeAndWaitForTxHash(postponedTxHash);
void subscribeAndWaitForTxHash(postponedTxHash);
}

subscribeToStorage(`mailbox.${clientAddr}`, (err, storageValue) => {
Expand Down Expand Up @@ -692,15 +692,20 @@ ${chainID} chain does not yet know of address ${clientAddr}${adviseEgress(
// Wait for the transaction to be included in a block.
const txHash = out.txhash;

waitForTxHash(txHash).then(txResult => {
// The result had an error code (not 0 or undefined for success).
if (txResult.code) {
waitForTxHash(txHash)
.then(txResult => {
// The result had an error code (not 0 or undefined for success).
if (txResult.code) {
// eslint-disable-next-line no-use-before-define
failedSend(
assert.error(`Error in tx processing: ${txResult.log}`),
);
}
})
.catch(err =>
// eslint-disable-next-line no-use-before-define
failedSend(
assert.error(`Error in tx processing: ${txResult.log}`),
);
}
});
failedSend(assert.error(`Error in tx processing: ${err}`)),
);

// We submitted the transaction to the mempool successfully.
// Preemptively increment our sequence number to avoid needing to
Expand Down Expand Up @@ -778,7 +783,7 @@ ${chainID} chain does not yet know of address ${clientAddr}${adviseEgress(
updateCount || Fail`Sending unexpectedly finished!`;

await sendFromMessagePool().then(successfulSend, failedSend);
recurseEachSend(updateCount);
void recurseEachSend(updateCount);
};

// Begin the sender when we get the first (empty) mailbox update.
Expand Down
4 changes: 2 additions & 2 deletions packages/solo/src/vat-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function buildRootObject(vatPowers) {
commandDevice = d;

const replHandler = getReplHandler(replObjects, send);
registerURLHandler(replHandler, '/private/repl');
void registerURLHandler(replHandler, '/private/repl');

// Assign the captp handler.
const captpHandler = Far('captpHandler', {
Expand All @@ -127,7 +127,7 @@ export function buildRootObject(vatPowers) {
return harden(exported);
},
});
registerURLHandler(captpHandler, '/private/captp');
void registerURLHandler(captpHandler, '/private/captp');
},

registerURLHandler,
Expand Down
2 changes: 1 addition & 1 deletion packages/solo/test/captp-fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export async function makeFixture(PORT, noisy = false) {
// We only reject if the child exits before CapTP is established.
reject(Error(`CapTP fixture exited with ${code}`));
});
tryConnect(resolve, reject);
void tryConnect(resolve, reject);
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/swingset-liveslots/src/liveslots.js
Original file line number Diff line number Diff line change
Expand Up @@ -1602,7 +1602,7 @@ function build(
// *not* directly wait for the userspace function to complete, nor for
// any promise it returns to fire.
const p = Promise.resolve(delivery).then(unmeteredDispatch);
p.finally(() => (complete = true));
void p.finally(() => (complete = true));

// Instead, we wait for userspace to become idle by draining the
// promise queue. We clean up and then examine/return 'p' so any
Expand Down
13 changes: 8 additions & 5 deletions packages/xsnap/src/xsnap.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export async function xsnap(options) {
sourceStream.pipe(destStream, { end: false });

done = finished(sourceStream);
done.catch(noop).then(() => sourceStream.unpipe(destStream));
void done.catch(noop).then(() => sourceStream.unpipe(destStream));
};

return harden({
Expand Down Expand Up @@ -258,7 +258,7 @@ export async function xsnap(options) {
await loadSnapshotHandler?.afterSpawn(snapshotLoadStream);

if (loadSnapshotHandler) {
vatExit.promise.catch(noop).then(() => {
void vatExit.promise.catch(noop).then(() => {
if (loadSnapshotHandler) {
const { cleanup } = loadSnapshotHandler;
loadSnapshotHandler = undefined;
Expand Down Expand Up @@ -458,10 +458,13 @@ export async function xsnap(options) {
const handle = await fs.open(snapPath, 'w+');
// @ts-expect-error 'close' event added in Node 15.4
handle.on('close', () => {
fs.unlink(snapPath);
// Safe to ignore the result because we are skipping to to clean up the temp directory.
void fs.unlink(snapPath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment in this case that it's safe to ignore the result because it simply means we may not have cleaned up a temp directory.

});
sourceStream = handle.createReadStream();
finished(output).finally(() => sourceStream.destroy());
finished(output)
.finally(() => sourceStream.destroy())
.catch(noop);
} else {
sourceStream = snapshotSaveStream;
snapPath = `@${SNAPSHOT_SAVE_FD}`;
Expand All @@ -470,7 +473,7 @@ export async function xsnap(options) {
// ensuring that any previous save stream usage has ended. However we
// must start the flow before receiving the command's response or the
// xsnap process would block on a full pipe, causing an IPC deadlock.
batonKit.promise.then(maybePipe);
batonKit.promise.then(maybePipe, noop);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe the same issue here? I definitely want @mhofman to drive this part, I don't understand the whole "baton" thing very well

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is valid, it silences a potential rejection of the baton that would bottom out somewhere else.

}

const cleanup = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/xsnap/src/xsrepl.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ async function main() {
return vat.close();
}

main();
await main().catch(err => console.log(err));
2 changes: 1 addition & 1 deletion packages/xsnap/test/fixture-xsnap-script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint @typescript-eslint/no-floating-promises: "warn" */
/* global issueCommand */
(async () => {
void (async () => {
issueCommand(new TextEncoder().encode('Hello, World!').buffer);
})();
Loading