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

[spaceship] refresh token and retry on authorization errors #19502

Merged
merged 2 commits into from Apr 12, 2022

Conversation

andersonvom
Copy link
Contributor

@andersonvom andersonvom commented Oct 20, 2021

Checklist

  • I've run bundle exec rspec from the root directory to see all new and existing tests pass
  • I've followed the fastlane code style and run bundle exec rubocop -a to ensure the code style is valid
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary.

Motivation and Context

Apple seems to be revoking tokens before their expiration dates. Several
users reporting problems on issue #19072 were likely affected by
it. Sometimes changing the token duration will work around the problem,
as the tokens are likely being revoked later in the future and allowing
the wait to complete.

This can be seen in practice by adding a @token.refresh! couple of extra log
messages to api_client.rb right at the point where we get an
UnauthorizedAccessError:

INFO  [2021-10-19 18:38:31.74]: Successfully uploaded the new binary to App Store Connect
INFO  [2021-10-19 18:38:31.74]: If you want to skip waiting for the processing to be finished, use the `skip_waiting_for_build_processing` option
INFO  [2021-10-19 18:38:31.74]: Note that if `skip_waiting_for_build_processing` is used but a `changelog` is supplied, this process will wait for the build to appear on AppStoreConnect, update the changelog and then skip the remaining of the processing steps.
DEBUG [2021-10-19 18:38:31.82]: App Platform (ios)
INFO  [2021-10-19 18:38:31.92]: Waiting for processing on... app_id: 1370986669, app_version: 2.23.2, build_version: 262025, platform: IOS
WARN  [2021-10-19 18:38:32.26]: Read more information on why this build isn't showing up yet - https://github.com/fastlane/fastlane/issues/14997
INFO  [2021-10-19 18:38:32.26]: Waiting for the build to show up in the build list - this may take a few minutes (check your email for processing issues if this continues)
INFO  [2021-10-19 18:39:02.70]: Waiting for the build to show up in the build list - this may take a few minutes (check your email for processing issues if this continues)

token expired?: false  - expiration: 2021-10-19 18:45:04 -0400
Token has expired, has been revoked, or is invalid! Trying to refresh

INFO  [2021-10-19 18:39:33.26]: Waiting for the build to show up in the build list - this may take a few minutes (check your email for processing issues if this continues)
INFO  [2021-10-19 18:40:03.69]: Waiting for the build to show up in the build list - this may take a few minutes (check your email for processing issues if this continues)
INFO  [2021-10-19 18:40:34.33]: Waiting for the build to show up in the build list - this may take a few minutes (check your email for processing issues if this continues)
INFO  [2021-10-19 18:41:04.76]: Waiting for the build to show up in the build list - this may take a few minutes (check your email for processing issues if this continues)
INFO  [2021-10-19 18:41:35.21]: Waiting for the build to show up in the build list - this may take a few minutes (check your email for processing issues if this continues)
INFO  [2021-10-19 18:42:05.67]: Waiting for the build to show up in the build list - this may take a few minutes (check your email for processing issues if this continues)

token expired?: false  - expiration: 2021-10-19 18:47:52 -0400
Token has expired, has been revoked, or is invalid! Trying to refresh

INFO  [2021-10-19 18:42:36.34]: Waiting for the build to show up in the build list - this may take a few minutes (check your email for processing issues if this continues)
INFO  [2021-10-19 18:43:06.80]: Waiting for the build to show up in the build list - this may take a few minutes (check your email for processing issues if this continues)
INFO  [2021-10-19 18:43:37.23]: Waiting for the build to show up in the build list - this may take a few minutes (check your email for processing issues if this continues)

The logs above show that, even though the current token is not expired, the
appconnect API responds with a 401 and the process would otherwise fail.

Description

This refreshes the token and adds retries to UnauthorizedAccessError
before ultimately raising the error if it still continues to fail.

@google-cla
Copy link

google-cla bot commented Oct 20, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@andersonvom
Copy link
Contributor Author

@joshdholtz pinging you here since you seem to have made plenty of changes to this file

@DuMaM
Copy link
Contributor

DuMaM commented Dec 30, 2021

@crazymanish Sorry for pinging you but this PR could help for quite a big amount of people. Could you take a look on it?

@Abdullah-TH
Copy link

Hopefully someone will merge this soon. I'm facing the same issue all the time.

@andersonvom
Copy link
Contributor Author

Hi folks, just friendly bumping this up in case it fell through the cracks. Is there anything else I need to do in order to get this merged? (cc @crazymanish @joshdholtz)

@nekrich
Copy link
Contributor

nekrich commented Feb 10, 2022

Hey there, this PR looks great, is easy to review, all issues are solved. And the best part is that it really works.
Can we get it merged, please 🙏 ?

I'm afraid it got lost (cc @crazymanish )

@ryanjwessel
Copy link

I can add that my team has been using a forked version of fastlane that includes these changes for a few months.

The changes in this Pull Request eliminated all flakiness from our App Store Connect uploads.

@mathaeus
Copy link

mathaeus commented Mar 2, 2022

Hi, bumping this again.
Any chance of this getting merged and released? @crazymanish

We started facing random auth errors this morning. The duration workaround from #19072 seems to work, but who knows for how long.

@DuMaM
Copy link
Contributor

DuMaM commented Mar 2, 2022

@joshdholtz Could you please take look on it? :) It's merge ready, and it was also checked by many users. :D Pls 🙏

dragomir-ivanov-212 added a commit to Trading212Dev/fastlane that referenced this pull request Mar 3, 2022
@maxidela
Copy link

maxidela commented Mar 7, 2022

We are getting this issue, 1 every 3/4 times which causes our pipeline to fail even though app was uploaded. Can this be merged pls

@SprengerS
Copy link

Please review this request. This bug is very frustrating

@JencirJamal
Copy link

Please review and merge this PR. We also started to experience the same problem from last week onwards. Would like this fix to be merged soon.

@jesperjohansson
Copy link

We have also started getting the issue with expired API token recently

@0xmahesh
Copy link

Hi, can we get this merged soon?

@Neilfau
Copy link

Neilfau commented Mar 10, 2022

Need this merged ASAP... getting the error a lot in last few days.

@joaopmarquesini
Copy link

+1 on merging this, getting a lot of wrong prematurely expired tokens lately

@rogerluan
Copy link
Member

I'm onboard with your reasoning @andersonvom 💪
@nekrich thanks for looking into it 🙏

@rogerluan
Copy link
Member

Friendly ping @joshdholtz to perhaps bump the priority of this PR 🙏 🙇

@joshdholtz
Copy link
Member

Ah thank you thank you!! Will look at first thing tomorrow morning 😁

@joshdholtz joshdholtz self-assigned this Apr 12, 2022
@joshdholtz joshdholtz changed the title Refresh token and retry on authorization errors [spaceship] refresh token and retry on authorization errors Apr 12, 2022
Copy link
Member

@joshdholtz joshdholtz left a comment

Choose a reason for hiding this comment

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

Thanks so much for this PR! And so sorry this one slipped my eyes 😔 I'll get this released this week! Really appreciate the contribution ❤️

@joshdholtz joshdholtz merged commit baeb595 into fastlane:master Apr 12, 2022
@andersonvom andersonvom deleted the retry-on-auth-error branch April 12, 2022 18:01
@andersonvom
Copy link
Contributor Author

Alriiiight! 🎉

No worries at all, @joshdholtz! Thanks for looking into this and getting it released shortly! And thank you all who contributed with reviews and tests over time! 🏆

@fastlane-bot
Copy link

Hey @andersonvom 👋

Thank you for your contribution to fastlane and congrats on getting this pull request merged 🎉
The code change now lives in the master branch, however it wasn't released to RubyGems yet.
We usually ship about once a week, and your PR will be included in the next one.

Please let us know if this change requires an immediate release by adding a comment here 👍
We'll notify you once we shipped a new release with your changes 🚀

@rzulkoski
Copy link

Do we have an ETA when the next release will ship that includes this fix @joshdholtz?

Thanks! ❤️

@joshdholtz
Copy link
Member

Hey! Planning a new release most likely tomorrow 💪

@mike-gallego
Copy link

Is the release out?

@trev91
Copy link

trev91 commented Apr 20, 2022

@joshdholtz Thanks for getting this merged! I hope to be the last person to need to comment on this issue ;) Any update on the release here? My team's hoping we can update the gem for a little more stability in our pipelines tomorrow.

@joshdholtz
Copy link
Member

Sorry! Going out today sometime. I had some eye issues last night and struggled to look at my computer screen so had to stop ☹️

@joshdholtz
Copy link
Member

Hey fam! Just wanted to let you all know that this is getting released tonight 😊 I'm going to review and merge a few more things but this will for sure go out tonight.

Sorry again for the slowness. Life can get a little hard but still shouldn't have kept this one merged and unreleased for so long 😓

Will update here again when release!

@benkane
Copy link

benkane commented Apr 21, 2022

You're doing great, Josh. Thank you 🙂

@joshdholtz
Copy link
Member

This should be out in 2.205.2 now! If you are using the brew version, it will probably be out later tomorrow when they approve it 😊

@fastlane-bot
Copy link

Congratulations! 🎉 This was released as part of fastlane 2.205.2 🚀

@crazymanish
Copy link
Member

I am sorry, i had my GH notifications off so i never got any notification on mention...Just turned on my GH notifications for mention so will be fast to reply next time 🙇‍♂️ 😇

today i came here from discussion #20101 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet