rubyonjets/jets

OpenSSL error when doing a POST with HTTParty

AlexGascon opened this issue · 1 comments

Checklist

  • Upgrade Jets: Are you using the latest version of Jets? This allows Jets to fix issues fast. There's a jets upgrade command that makes this a simple task. There's also an Upgrading Guide: http://rubyonjets.com/docs/upgrading/
  • Reproducibility: Are you reporting a bug others will be able to reproduce and not asking a question. If you're unsure or want to ask a question, do so on https://community.rubyonjets.com
  • Code sample: Have you put together a code sample to reproduce the issue and make it available? Code samples help speed up fixes dramatically. If it's an easily reproducible issue, then code samples are not needed. If you're unsure, please include a code sample.

My Environment

Software Version
Operating System Ubuntu 18.10
Jets 1.9.30
Ruby 2.5

Expected Behaviour

Making an HTTP request succeeds

Current Behavior

Making an HTTP request results in an SSL error

Step-by-step reproduction instructions

I'm encountering an SSL error when trying to make an HTTP request from the Lambda function. This is the traceback of the error in Lambda

{
  "errorMessage": "SSL_connect returned=1 errno=0 state=error: certificate verify failed (certificate has expired)",
  "errorType": "Function<OpenSSL::SSL::SSLError>",
  "stackTrace": [
    "/var/lang/lib/ruby/2.5.0/net/protocol.rb:44:in `connect_nonblock'",
    "/var/lang/lib/ruby/2.5.0/net/protocol.rb:44:in `ssl_socket_connect'",
    "/var/lang/lib/ruby/2.5.0/net/http.rb:985:in `connect'",
    "/var/lang/lib/ruby/2.5.0/net/http.rb:920:in `do_start'",
    "/var/lang/lib/ruby/2.5.0/net/http.rb:909:in `start'",
    "/var/lang/lib/ruby/2.5.0/net/http.rb:1458:in `request'",
    "/opt/ruby/gems/2.5.0/gems/httparty-0.17.3/lib/httparty/request.rb:145:in `perform'",
    "/opt/ruby/gems/2.5.0/gems/httparty-0.17.3/lib/httparty.rb:594:in `perform_request'",
    "/opt/ruby/gems/2.5.0/gems/httparty-0.17.3/lib/httparty.rb:524:in `post'",
    "/opt/ruby/gems/2.5.0/gems/httparty-0.17.3/lib/httparty.rb:631:in `post'",
<My code here>

Unfortunately, I haven't been able to reproduce it on my local environment: the same code works perfectly fine on it, which discards an actual issue with the server certificate as the error indicates.

There are a few issues that make this problem strange:

  • The error is not consistent: currently it is raised from a request done from an external gem, but a few weeks ago it started happening all of a sudden from a request in my actual codebase without having done any change on it. That time the problem disappeared by itself after a day or two. However, when it starts happening, it happens on every single request.
  • The error is also present if I do an HTTP request or skip server verification: Despite it mentions an SSL certificate, if I make the calls to the HTTP endpoint or specify the verify_peer: false option in HTTParty the error is still raised. This leads me to believe that it may be a problem on the client-side instead of something in the endpoint I'm requesting.

I know that with this information it's very difficult to pinpoint the root cause, but the fact that it's completely impossible to reproduce on my local environment leads me to believe that the issue has to be either on the gems that are uploaded to the Lambda or on the Lambda itself, so I wanted to ask in case you have any lead that may at least help clarify the situation. In case it's helpful, these are the links to my Gemfile and my Gemfile.lock

Let me know if there's any other information that I can provide to help debug the issue. Thanks in advance!

Finally I contacted AWS Support and they confirmed that the error is on the Lambda environment, sorry for the trouble!