-
Notifications
You must be signed in to change notification settings - Fork 212
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
Conversation
786e96f
to
b585fe9
Compare
There was a problem hiding this 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.
packages/xsnap/src/xsnap.js
Outdated
@@ -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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
packages/xsnap/src/xsnap.js
Outdated
@@ -264,7 +264,7 @@ export async function xsnap(options) { | |||
loadSnapshotHandler = undefined; | |||
return cleanup(); | |||
} | |||
}); | |||
}, noop); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
packages/xsnap/src/xsrepl.js
Outdated
@@ -97,4 +97,4 @@ async function main() { | |||
return vat.close(); | |||
} | |||
|
|||
main(); | |||
await main(); |
There was a problem hiding this comment.
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.
There was a problem hiding this 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)
packages/xsnap/src/xsnap.js
Outdated
@@ -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); |
There was a problem hiding this comment.
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.
packages/xsnap/src/xsnap.js
Outdated
@@ -264,7 +264,7 @@ export async function xsnap(options) { | |||
loadSnapshotHandler = undefined; | |||
return cleanup(); | |||
} | |||
}); | |||
}, noop); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
packages/xsnap/src/xsnap.js
Outdated
}); | ||
sourceStream = handle.createReadStream(); | ||
finished(output).finally(() => sourceStream.destroy()); | ||
void finished(output).finally(() => sourceStream.destroy()); |
There was a problem hiding this comment.
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.
void finished(output).finally(() => sourceStream.destroy()); | |
finished(output).finally(() => sourceStream.destroy()).catch(noop); |
There was a problem hiding this 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!
There was a problem hiding this 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!
32002d8
to
e852eeb
Compare
e852eeb
to
f5fb0ce
Compare
closes: #8210
refs: #6000
Security Considerations
Scaling Considerations
Documentation Considerations
Testing Considerations
Upgrade Considerations