Skip to content
This repository has been archived by the owner on Nov 19, 2018. It is now read-only.

spaceship ITC client hardening (#150). #235

Merged
merged 1 commit into from
Feb 20, 2016

Conversation

lacostej
Copy link
Contributor

@lacostej lacostej commented Feb 7, 2016

The following set of patches allow to make ITC communication more resilient.

It:

  • handles better ITC timeouts (by extending the default timeout)
  • handles HTTP/SSL failures (by retrying them) those are probably openssl&client dependent
  • handles ITC 401 issues (by login again)
  • handles better temporary issue to save (by retrying again)

Several things are to be discussed, in particular, how to implement re-login in the case of spaceship client#login being used with 2 parameters (password is currently not remembered in that case)

Last run:

49 'Loops' for delivering 30 screenshots
71 retries
ITC temporary save error received: 'We're temporarily unable to save your changes. Please try again later.'. Retrying after 60 seconds (remaining: 1)...
ESC[37m[06:58:46]: ESC[0mFailed / completed after 9 hour(s) 38 min(s) 11 sec(s)
/Users/lacostej/.rvm/gems/ruby-2.2.4/gems/spaceship-0.19.3/lib/spaceship/tunes/tunes_client.rb:218:in `handle_itc_response': We're temporarily unable to save your changes. Please try again later. (Spaceship::TunesClient::ITunesConnectTemporaryError)
        from /Users/lacostej/.rvm/gems/ruby-2.2.4/gems/spaceship-0.19.3/lib/spaceship/tunes/tunes_client.rb:361:in `block in update_app_version!'
        from /Users/lacostej/.rvm/gems/ruby-2.2.4/gems/spaceship-0.19.3/lib/spaceship/tunes/tunes_client.rb:795:in `call'

It is resilient but slow.

Updated with unit tests.

Note that the issue mentioned here, is tentatively covered by df4b3b8. This is one solution, but I am unsure we want to solve it that way.

raise ex # re-raise the exception
end

private

# this mostly for troubleshooting while harderning the client
def debug_count_recovered
@recoveriesCount = (@recoveriesCount || 0 ) + 1

Choose a reason for hiding this comment

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

Space inside parentheses detected.
Use snake_case for variable names.

return block.call
rescue Spaceship::TunesClient::ITunesConnectTemporaryError => ex
unless (tries -= 1).zero?
msg = "ITC temporary save error received: '#{ex.message}'. Retrying after 60 seconds (remaining: #{tries})..."
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have access to the tries variable here? If yes, we could start by waiting just like a few seconds, and then go up to 1-2 minutes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes we could. Right now I am aiming for resilience, then fine tuning. In the end I would love to move some of this into either a faraday middleware, or using a custom more declarative "retrier".

For example, out of the last 5 runs, they all ended up failing here. I increased it to 60 seconds and it still fails sometimes.

Here are the last 2, with a 60 second sleep in between retries:

ITC temporary save error received: 'We're temporarily unable to save your changes. Please try again later.'. Retrying after 60 seconds (remaining: 1)...
ESC[37m[19:47:24]: ESC[0mFailed / completed after 5 hour(s) 16 min(s) 32 sec(s)
/Users/lacostej/.rvm/gems/ruby-2.2.4/gems/spaceship-0.19.3/lib/spaceship/tunes/tunes_client.rb:218:in `handle_itc_response': We're temporarily unable to save your changes. Please try again later. (Spaceship::TunesClient::ITunesConnectTemporaryError)
        from /Users/lacostej/.rvm/gems/ruby-2.2.4/gems/spaceship-0.19.3/lib/spaceship/tunes/tunes_client.rb:361:in `block in update_app_version!'
ITC temporary save error received: 'We're temporarily unable to save your changes. Please try again later.'. Retrying after 60 seconds (remaining: 1)...
ESC[37m[21:20:34]: ESC[0mFailed / completed after 1 hour(s) 33 min(s) 8 sec(s)
/Users/lacostej/.rvm/gems/ruby-2.2.4/gems/spaceship-0.19.3/lib/spaceship/tunes/tunes_client.rb:218:in `handle_itc_response': We're temporarily unable to save your changes. Please try again later. (Spaceship::TunesClient::ITunesConnectTemporaryError)
        from /Users/lacostej/.rvm/gems/ruby-2.2.4/gems/spaceship-0.19.3/lib/spaceship/tunes/tunes_client.rb:361:in `block in update_app_version!'
        from /Users/lacostej/.rvm/gems/ruby-2.2.4/gems/spaceship-0.19.3/lib/spaceship/tunes/tunes_client.rb:795:in `call'

In the one that lasted 5 h 30 min, I had

  • 0 timeout / connection failed (they appear more seldomly now given the 300 seconds
  • 20+ auth lost
  • 6 unable to save (last one fatal)
    connection timeout)

@KrauseFx
Copy link
Contributor

KrauseFx commented Feb 7, 2016

This looks really promising, great job. Pinging @snatchev, as he's also a spaceship expert 👍


describe Spaceship::Client do
class TestClient < Spaceship::Client

Choose a reason for hiding this comment

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

Extra empty line detected at class body beginning.


ideas
* parametrize default timeout ?
* make default timeout client specific ?
Copy link
Contributor

Choose a reason for hiding this comment

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

Before merging this needs to be moved out into separate GitHub issues. I can add a stability tag for you 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean the whole file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure I didn't intend to submit it as it.

@KrauseFx
Copy link
Contributor

This looks great, thanks again for this PR, I added some comments 👍

msg = "ITC temporary save error received: '#{ex.message}'. Retrying after 60 seconds (remaining: #{tries})..."
puts msg
logger.warn msg
sleep 60 unless defined?SpecHelper # unless FastlaneCore::Helper.is_test?

Choose a reason for hiding this comment

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

Space after keyword defined? is missing.

@lacostej lacostej mentioned this pull request Feb 13, 2016
@snatchev
Copy link
Contributor

@lacostej looks good to me.

@KrauseFx
Copy link
Contributor

I just did the final review, this looks perfect from my side. Let's squash the commits and I'll ship a new version 🚀

lacostej added a commit to lacostej/spaceship that referenced this pull request Feb 19, 2016
lacostej added a commit to lacostej/spaceship that referenced this pull request Feb 19, 2016
* handles better ITC timeouts (by extending the default timeout to 5 min)
* handles HTTP/SSL failures (by retrying them) those are probably openssl&client dependent
* handles ITC 401 issues (by login again)
* handles better temporary ITC issue to save ('try again later') (by ... retrying again)

Also
* cache some of the data to avoid querying the server too much

Assisted by Krzysztof Daniszewski <krzysztof@daniszewski.it>
* handles better ITC timeouts (by extending the default timeout to 5 min)
* handles HTTP/SSL failures (by retrying them) those are probably openssl&client dependent
* handles ITC 401 issues (by login again)
* handles better temporary ITC issue to save ('try again later') (by ... retrying again)

Also
* cache some of the data to avoid querying the server too much

Assisted by Krzysztof Daniszewski <krzysztof@daniszewski.it>
KrauseFx added a commit that referenced this pull request Feb 20, 2016
spaceship ITC client hardening (#150).
@KrauseFx KrauseFx merged commit 7a539e1 into fastlane-old:master Feb 20, 2016
@KrauseFx
Copy link
Contributor

Thanks again for this 👍

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

Successfully merging this pull request may close these issues.

4 participants