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

handle floating promises in governance #5584

Merged
merged 3 commits into from
Jul 18, 2022
Merged

Conversation

turadg
Copy link
Member

@turadg turadg commented Jun 13, 2022

no ticket, busy hands during standup

Description

Handle floating promises.

Security Considerations

--

Documentation Considerations

--

Testing Considerations

CI

@turadg turadg requested a review from Chris-Hibbert June 13, 2022 17:46
@@ -10,7 +10,7 @@ import { Far } from '@endo/marshal';
/** @type {CloseVoting} */
export const scheduleClose = (closingRule, closeVoting) => {
const { timer, deadline } = closingRule;
E(timer).setWakeup(
return E(timer).setWakeup(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return E(timer).setWakeup(
void E(timer).setWakeup(

CloseVoting claims to have return type void

@@ -228,10 +228,16 @@ const makeBootstrap = (argv, cb, vatPowers) => async (vats, devices) => {
const [testName] = argv;
switch (testName) {
case 'committeeBinaryStart':
committeeBinaryStart(zoe, voterCreator, timer, log, installations);
await committeeBinaryStart(zoe, voterCreator, timer, log, installations);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think await is doing anything helpful here. Wouldn't void be clearer?
[same below]

Copy link
Member Author

Choose a reason for hiding this comment

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

It's preserving the stack trace if committeeBinaryStart fails. Without these awaits, makeBootstrap will complete as soon as the case functions are called. If they fail it will throw in Node as an unhandled promise rejection.

I think if they fail then makeBootstrap should also fail.

@@ -43,7 +43,7 @@ const build = async (log, zoe) => {
},
});
const subscription = E(electoratePublicFacet).getQuestionSubscription();
observeIteration(subscription, votingObserver);
await observeIteration(subscription, votingObserver);
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly here. Isn't await misleading? The point of the code is to set the observer off on it's own, and return the facet. Why is await better?

Copy link
Member Author

@turadg turadg Jun 15, 2022

Choose a reason for hiding this comment

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

Yeah, I was on the fence about this case. The point is to kick off the observer and not expect anything back, but what if it fails? Like above, awaiting maintains the stack trace.

If we don't want to detect that failure, then I think we should change observeIteration (the called function) to be synchronous instead of dropping the promise in every call.

From

* @returns {Promise<undefined>}
*/
export const observeIteration = (asyncIterableP, iterationObserver) => {
const iteratorP = E(asyncIterableP)[Symbol.asyncIterator]();
return observeIterator(iteratorP, iterationObserver);
};
to

 */
export const observeIteration = (asyncIterableP, iterationObserver) => {
  const iteratorP = E(asyncIterableP)[Symbol.asyncIterator]();
  void observeIterator(iteratorP, iterationObserver);
};

Which do you think is better?

Copy link
Contributor

Choose a reason for hiding this comment

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

Attempting to channel @erights: I expect some callers to want to be able to react to the results. In this test, it seems that the test should be conditional on results of the observation, so it doesn't really need to detect a failure in the adapter.

@@ -390,7 +390,7 @@ const makeBootstrap = (argv, cb, vatPowers) => async (vats, devices) => {

await E(timer).tick();
await E(timer).tick();
E.when(
await E.when(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
await E.when(
void E.when(

The test doesn't want to wait here. It wants these logs requests to fire later.

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks, I was wondering why they were failing ;-)

@@ -443,7 +443,7 @@ const makeBootstrap = (argv, cb, vatPowers) => async (vats, devices) => {

await E(timer).tick();
await E(timer).tick();
E.when(
await E.when(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
await E.when(
void E.when(

@turadg turadg force-pushed the ta/governance-promises branch from 9f49ec6 to 1563e55 Compare July 7, 2022 21:18
@turadg turadg requested a review from Chris-Hibbert July 7, 2022 22:11
@turadg turadg added the automerge:rebase Automatically rebase updates, then merge label Jul 18, 2022
@turadg turadg force-pushed the ta/governance-promises branch from 1563e55 to 42e0c03 Compare July 18, 2022 16:51
@mergify mergify bot merged commit 12e1527 into master Jul 18, 2022
@mergify mergify bot deleted the ta/governance-promises branch July 18, 2022 17:52
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.

2 participants