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

fix: force setMetadata calls to use promise version, invoke callbacks manually #2000

Merged
merged 5 commits into from Jul 13, 2022

Conversation

ddelgrosso1
Copy link
Contributor

@ddelgrosso1 ddelgrosso1 commented Jun 30, 2022

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

Rationale for this change:

setMetadata is a conditionally idempotent operation. Currently if no precondition is provided we flip a flag to turn off retries. However, since setMetadata is promisified we are seeing behavior where the flag is getting flipped back before the operation completes. This is causing incorrect behavior. I am changing the internal calls to wait for the promise to finish before flipping the flag back.

@ddelgrosso1 ddelgrosso1 requested review from a team as code owners June 30, 2022 20:15
@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: storage Issues related to the googleapis/nodejs-storage API. labels Jun 30, 2022
@ddelgrosso1 ddelgrosso1 added the owlbot:run Add this label to trigger the Owlbot post processor. label Jun 30, 2022
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jun 30, 2022
Copy link
Contributor

@shaffeeullah shaffeeullah left a comment

Choose a reason for hiding this comment

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

Can you also add a description to this PR to explain why this change is needed? :)

src/bucket.ts Outdated
this.setMetadata({lifecycle: {rule: newLifecycleRules}}, callback);
this.storage.retryOptions.autoRetry = this.instanceRetryValue;
this.setMetadata({lifecycle: {rule: newLifecycleRules}})
.then(resp => callback!(null, resp))
Copy link
Contributor

Choose a reason for hiding this comment

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

will callbacks always be provided? (guessing yes, but just wanted to double check this)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In some situations there is no guarantee, in those places I have added a check and utilize util.noop as the callback.

@@ -3654,22 +3654,6 @@ describe('File', () => {
});
});

it('should execute callback with error & API response', done => {
Copy link
Contributor

Choose a reason for hiding this comment

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

For future reference, spoke with @ddelgrosso1 and determined that this case does not exist and that it would be safe to remove this test.

@ddelgrosso1 ddelgrosso1 added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Jul 1, 2022
@ddelgrosso1
Copy link
Contributor Author

Marking do not merge until I fix this up and run a bunch of tests to make sure this doesn't break current behavior.

@ddelgrosso1 ddelgrosso1 added the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 1, 2022
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 1, 2022
@ddelgrosso1
Copy link
Contributor Author

Been running some tests locally and from what I can tell things look the same as they were. @danielbankhead would you mind giving this PR a look as well?

Copy link
Member

@danielbankhead danielbankhead left a comment

Choose a reason for hiding this comment

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

LGTM; maybe in a future refactor we can isolate the method-level retry count from the instance's retry count (perhaps via an optional param or property)

@ddelgrosso1 ddelgrosso1 removed do not merge Indicates a pull request not ready for merge, due to either quality or timing. labels Jul 12, 2022
@ddelgrosso1 ddelgrosso1 merged commit f488647 into googleapis:main Jul 13, 2022
@ddelgrosso1 ddelgrosso1 deleted the fix-setmetadata branch July 13, 2022 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/nodejs-storage API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants