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

Conversation

toliaqat
Copy link
Contributor

@toliaqat toliaqat commented Aug 17, 2023

closes: #8210
refs: #6000

Security Considerations

Scaling Considerations

Documentation Considerations

Testing Considerations

AGORIC_ESLINT_TYPES=true yarn lint

Upgrade Considerations

@toliaqat toliaqat force-pushed the 8210-tl-resolve-floating-promises branch from 786e96f to b585fe9 Compare August 17, 2023 08:09
@toliaqat toliaqat marked this pull request as ready for review August 17, 2023 18:01
Copy link
Member

@warner warner left a comment

Choose a reason for hiding this comment

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

Looks good.. modulo the then(.., noop) questions, I think the code changes are fine.

In the future, we may need to cherry-pick portions of this for selective deployment purposes. Could you split the PR into multiple commits, to avoid co-mingling changes to packages that may need to be deployed separately?

  • one commit for internal
  • one commit for SwingSet and swingset-liveslots
  • one for xsnap
  • one for cosmic-swingset and solo

I'd recommend waiting for @mhofman to chime in, then both split it into four commits and rebase it onto current trunk. After that, feel free to land.

@@ -152,7 +152,7 @@ export async function xsnap(options) {
sourceStream.pipe(destStream, { end: false });

done = finished(sourceStream);
done.catch(noop).then(() => sourceStream.unpipe(destStream));
done.catch(noop).then(() => sourceStream.unpipe(destStream), noop);
Copy link
Member

Choose a reason for hiding this comment

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

Huh, I'm guessing we needed the errback (second arg) in the .then() because the linter doesn't believe that noop will never throw? But, why didn't it complain that the promise returned by .then is similarly ungrounded?

@mhofman is the expert on this code, but I'm guessing that a void in front of the whole thing would be reasonable, and if that addresses whatever linter complaint that prompted the extra noop inside the then(), it might be a better fix overall.

Copy link
Member

Choose a reason for hiding this comment

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

That extra noop doesn't change a thing since we already have a .catch(noop) before that. And yeah it's more likely the linter would complain about sourceStream.unpipe(destStream) throwing (which it doesn't in practice). We can void the resulting promise if needed in this case.

@@ -264,7 +264,7 @@ export async function xsnap(options) {
loadSnapshotHandler = undefined;
return cleanup();
}
});
}, noop);
Copy link
Member

Choose a reason for hiding this comment

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

probably the same issue here

Copy link
Member

Choose a reason for hiding this comment

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

Same indeed

@@ -470,7 +470,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.

@@ -97,4 +97,4 @@ async function main() {
return vat.close();
}

main();
await main();
Copy link
Member

Choose a reason for hiding this comment

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

Oh, right, can we use top-level await now? Nice, I haven't internalized that yet.

I'd go one step further and do await main().catch(err => console.log(err)), because in my experience, simple errors or typos in functions called like this main() get lost, and the explicit catch is the only way to discover the problem.

Copy link
Member

@mhofman mhofman left a comment

Choose a reason for hiding this comment

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

Thanks for tackling these. Just a couple adjustments needed.

I'd like to have @michaelfig review the solo part (I didn't review)

@@ -152,7 +152,7 @@ export async function xsnap(options) {
sourceStream.pipe(destStream, { end: false });

done = finished(sourceStream);
done.catch(noop).then(() => sourceStream.unpipe(destStream));
done.catch(noop).then(() => sourceStream.unpipe(destStream), noop);
Copy link
Member

Choose a reason for hiding this comment

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

That extra noop doesn't change a thing since we already have a .catch(noop) before that. And yeah it's more likely the linter would complain about sourceStream.unpipe(destStream) throwing (which it doesn't in practice). We can void the resulting promise if needed in this case.

@@ -264,7 +264,7 @@ export async function xsnap(options) {
loadSnapshotHandler = undefined;
return cleanup();
}
});
}, noop);
Copy link
Member

Choose a reason for hiding this comment

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

Same indeed

@@ -458,10 +458,10 @@ 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);
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.

@@ -470,7 +470,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.

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

});
sourceStream = handle.createReadStream();
finished(output).finally(() => sourceStream.destroy());
void finished(output).finally(() => sourceStream.destroy());
Copy link
Member

Choose a reason for hiding this comment

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

so this in an interesting case of unhandled promise. In this case I believe we want to silence any error that may occur.

Suggested change
void finished(output).finally(() => sourceStream.destroy());
finished(output).finally(() => sourceStream.destroy()).catch(noop);

Copy link
Contributor

@FUDCo FUDCo left a comment

Choose a reason for hiding this comment

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

I second @warner's suggestion to use separate commits for separable stuff, but other than that it looks good. Hoorah for taking out the trash!

Copy link
Member

@michaelfig michaelfig left a comment

Choose a reason for hiding this comment

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

I reviewed the packages/solo changes, and they LGTM!

@toliaqat toliaqat force-pushed the 8210-tl-resolve-floating-promises branch 3 times, most recently from 32002d8 to e852eeb Compare August 25, 2023 05:59
@warner warner added the automerge:rebase Automatically rebase updates, then merge label Aug 28, 2023
@toliaqat toliaqat force-pushed the 8210-tl-resolve-floating-promises branch from e852eeb to f5fb0ce Compare August 28, 2023 19:39
@mergify mergify bot merged commit 0ed9127 into master Aug 28, 2023
66 of 67 checks passed
@mergify mergify bot deleted the 8210-tl-resolve-floating-promises branch August 28, 2023 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:rebase Automatically rebase updates, then merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

resolve all floating-promise warnings in kernel/platform packages
5 participants