nateleavitt / infusionsoft

Ruby Gem for the Infusionsoft API
MIT License
58 stars 70 forks source link

Rescue and retry on OpenSSL/Bad Gateway connection errors #71

Closed sneakernets closed 5 years ago

sneakernets commented 6 years ago

Referencing this topic: https://community.infusionsoft.com/t/intermittent-sll-connection-errors/31785/13 And issue #70 , This gem could benefit from a rescue/retry on API calls. From the forum topic:

def call(*args)
  result, retries = nil, 0
  begin
    silence_stream(STDERR) do
      result = xmlrpc.call *args
    end
  rescue OpenSSL::SSL::SSLError => e
    # According to IFS devs this is a timeout in the SSL handshake between us and them
    # So we should be able to retry this without ill effects
    if e.message =~ /SSL_connect SYSCALL/
      retries += 1
      if retries > 3
        log "*** INFUSION SSL ERROR: Handshake timeout (max retries reached) *** #{e.message}"
        raise e
      else
        log "*** INFUSION SSL ERROR: Handshake timeout (retry #{retries} of 3) *** #{e.message}"
        retry
      end
    else
      raise e
    end
  end

  result
end

I had been making my own rescue blocks on every single API call but that's just wayy too much code smell:

         begin
           Infusionsoft.contact_add_to_group(foo, bar)
         rescue OpenSSL::SSL::SSLError, Net::HTTPBadGateway => e
           puts "Infusionsoft error."
           puts e.message
           puts "Retrying in 5 seconds..."
           sleep(5)
           retry
         end
       end
nateleavitt commented 6 years ago

Hey... are you still seeing these errors? I'm using this gem in production on multiple servers and don't have this error.

nateleavitt commented 6 years ago

Just committed a fix to master. https://github.com/nateleavitt/infusionsoft/commit/14308a224ddaff2ad5327169dbee6fd9e0980366 Can you try pulling master into your project and see if it fixes the issue?

Replace gemfile entry with this: gem 'infusionsoft', :git => 'https://github.com/nateleavitt/infusionsoft.git'

If it works, I can build a new version of the gem.

sneakernets commented 6 years ago

I will try this ASAP! it'll take me a while to get to the server to update the gem but when I do I'll let you know!

nateleavitt commented 6 years ago

Ok.. let me know how it goes.

nateleavitt commented 6 years ago

@sneakernets - any update?

sneakernets commented 6 years ago

Unfortunately I have no longer access to that code, it was passed on to another team, but I'll let them know.

nateleavitt commented 6 years ago

Okay.. can anyone else test this that is seeing the problem?

nateleavitt commented 5 years ago

We are seeing these same errors in CustomerHub. So I am moving this forward to hopefully prevent these handshake issues until Infusionsoft gets it figured out.

nateleavitt commented 5 years ago

Have release gem v1.2.2 which catches and retries these errors.