Skip to content

Follow up on async vars - #3560

Closed
pmuens wants to merge 3 commits into
masterfrom
follow-up-on-async-vars
Closed

pmuens wants to merge 3 commits into
masterfrom
follow-up-on-async-vars

Conversation

@pmuens

@pmuens pmuens commented May 5, 2017 •

Copy link
Copy Markdown
Contributor

What did you implement:

This is a follow-up PR on #3554. The main purpose was to shrinkwrap and switch the whole codebase to Bluebird promises.

I think I uncovered a problem in the variable system. Seems like this code produces an infinite loop when using Bluebird.

The test which introduces the infinite loop is the one which tests for the usage of the custom variable syntax (see here).

You can see this by checking out this PR and adding a simple console.log() here (inside the if) and running the tests after that.

/cc @eahefnawy @brianneisler


functions() {
return new Promise((resolve) => {
return new BbPromise((resolve) => {

@arabold arabold May 5, 2017 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I suggest to use BbPromisy.try() instead of the new BbPromise anti-pattern:

return BbPromise.try(() => {
  this.deployedFunctions = this.deployedFunctions + 1;
})

This will also catch any synchronous throws and rejects your promise accordingly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for looking into this @arabold 👍 really helpful tips!

Comment thread lib/classes/Variables.js
_.deepMapValues(this.service, (property, propertyPath) => {
if (typeof property === 'string') {
const populateSingleProperty = new Promise((resolve) => this
const populateSingleProperty = new BbPromise((resolve) => this

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Let me try to decrypt this:

const populateSingleProperty = this.populateProperty(property, true)
  .then(newProperty => _.set(this.service, propertyPath, newProperty)
  .return();

This should be equal and seems more straight forward to me. new BbPromise() should really be avoided and isn't even necessary here. If any function doesn't return a BbPromise but a plain native Promise, it's easiest to wrap it using BbPromise.resolve(myNativePromiseFunc()).then(...).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I also think that the original code can cause unhandled rejections as there's no reject callback defined. If there's a rejection in populateProperty() then this little call would never finish as resolve() is never triggered IMO. I definitely suggest to rework the code into something similar to what I suggested above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Awesome! Thanks for the suggestion.

The current code in master causes a regression in the resolving step for the custom variable syntax. Having this (🔝 ) in place should prevent this and makes this more robust (it was uncovered "by accident")! 👍

@pmuens
pmuens force-pushed the follow-up-on-async-vars branch from f27661d to 675e371 Compare May 9, 2017 08:30
@pmuens pmuens mentioned this pull request May 10, 2017
@pmuens
pmuens force-pushed the follow-up-on-async-vars branch from 675e371 to 5c08d60 Compare May 10, 2017 08:37
@eahefnawy eahefnawy modified the milestones: 1.14, 1.13 May 10, 2017
@pmuens
pmuens force-pushed the follow-up-on-async-vars branch from 5c08d60 to 617ddee Compare May 12, 2017 07:49
@pmuens
pmuens force-pushed the follow-up-on-async-vars branch from 617ddee to 0e4b31a Compare May 17, 2017 10:48
@eahefnawy eahefnawy removed this from the 1.14 milestone May 24, 2017
@sammarks

sammarks commented May 31, 2017 •

Copy link
Copy Markdown
Contributor

Any progress on this one @pmuens? I can't use some of the new features of Serverless that I need to because of this issue. I can also help out if you point me in the right direction.

Edit: Took a stab at finishing this PR off here: #3709

@sammarks sammarks mentioned this pull request May 31, 2017
7 tasks done
@pmuens

pmuens commented May 31, 2017

Copy link
Copy Markdown
Contributor Author

Edit: Took a stab at finishing this PR off here: #3709

@sammarks That is super nice 👍 ! Thanks for that. 💪

I'll close this one since we'll be following-up the conversation in #3709

@pmuens pmuens closed this May 31, 2017
@pmuens
pmuens deleted the follow-up-on-async-vars branch May 31, 2017 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants