Search code examples
ruby-on-railsrubyruby-on-rails-4omniauth-facebookruby-2.5

Execution expired error with facebook login, using omniauth-facebook


Users are not able lo login from Facebook since July 3rd. I'm using omniauth-facebook. I tested login successfully from localhost (pointing to another FB test app). But in production the app shows this error:

Started GET "/auth/facebook" for 190.238.101.80 at 2019-07-10 17:53:51 -0500
I, [2019-07-10T17:53:51.594796 #4707]  INFO -- omniauth: (facebook) Request phase initiated.
Started GET "/auth/facebook/callback?code=AQAj5FOJuHu7UY656lbwZ4Sfcf_J_ZX9Z_t0wRT-LDfnPLU530zKj5CNGEK53yJ9maNj8O80fWgGmxCq4zWqBK7CPN-ovokGZVIvfY0KaqzNRXWOC20kH4KhkYOHjPyRh4tMYTIcHZ1a0BvHfbBLVolYECVtfD1OKJ2Xob07LCpS0SHNhYc6PA3rBAnb6GnkvOZI-8S7nwXIICdFoKu0BbHd-6L8_Dq-dPFTOpJDSWgmoJUBc65EyCnuw7NCI4IFP1UtxtOmB_QjuzRQV-voQs_SV6N97c2ICK_Qc-IqL_WBwqd54aEzdnW5UOsDV4Wo0jA&state=cee86047aecb4d282b80d33bbd0469815a17d25566167d95" for 190.238.101.80 at 2019-07-10 17:53:52 -0500
I, [2019-07-10T17:53:52.082829 #4707]  INFO -- omniauth: (facebook) Callback phase initiated.

Faraday::ConnectionFailed (execution expired):
  /usr/lib/ruby/2.5.0/net/http.rb:937:in `initialize'
  /usr/lib/ruby/2.5.0/net/http.rb:937:in `open'
  /usr/lib/ruby/2.5.0/net/http.rb:937:in `block in connect'
  /usr/lib/ruby/2.5.0/timeout.rb:103:in `timeout'
  /usr/lib/ruby/2.5.0/net/http.rb:935:in `connect'
  /usr/lib/ruby/2.5.0/net/http.rb:920:in `do_start'
  /usr/lib/ruby/2.5.0/net/http.rb:909:in `start'
  /usr/lib/ruby/2.5.0/net/http.rb:1458:in `request'
  faraday (0.15.4) lib/faraday/adapter/net_http.rb:87:in `perform_request'
  faraday (0.15.4) lib/faraday/adapter/net_http.rb:43:in `block in call'
  faraday (0.15.4) lib/faraday/adapter/net_http.rb:92:in `with_net_http_connection'
  faraday (0.15.4) lib/faraday/adapter/net_http.rb:38:in `call'
  faraday (0.15.4) lib/faraday/request/url_encoded.rb:15:in `call'
  faraday (0.15.4) lib/faraday/rack_builder.rb:143:in `build_response'
  faraday (0.15.4) lib/faraday/connection.rb:387:in `run_request'
  oauth2 (1.4.1) lib/oauth2/client.rb:99:in `request'
  oauth2 (1.4.1) lib/oauth2/client.rb:146:in `get_token'
  oauth2 (1.4.1) lib/oauth2/strategy/auth_code.rb:30:in `get_token'
  omniauth-oauth2 (1.6.0) lib/omniauth/strategies/oauth2.rb:89:in `build_access_token'
  omniauth-facebook (5.0.0) lib/omniauth/strategies/facebook.rb:110:in `build_access_token'
  omniauth-oauth2 (1.6.0) lib/omniauth/strategies/oauth2.rb:73:in `callback_phase'
  omniauth-facebook (5.0.0) lib/omniauth/strategies/facebook.rb:67:in `block in callback_phase'
  omniauth-facebook (5.0.0) lib/omniauth/strategies/facebook.rb:131:in `with_authorization_code!'
  omniauth-facebook (5.0.0) lib/omniauth/strategies/facebook.rb:66:in `callback_phase'
  omniauth (1.9.0) lib/omniauth/strategy.rb:238:in `callback_call'
  omniauth (1.9.0) lib/omniauth/strategy.rb:189:in `call!'
  omniauth (1.9.0) lib/omniauth/strategy.rb:169:in `call'
  omniauth (1.9.0) lib/omniauth/builder.rb:64:in `call'
  rack (1.6.11) lib/rack/etag.rb:24:in `call'
  rack (1.6.11) lib/rack/conditionalget.rb:25:in `call'
  rack (1.6.11) lib/rack/head.rb:13:in `call'
  actionpack (4.2.8) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.2.8) lib/action_dispatch/middleware/flash.rb:260:in `call'
  rack (1.6.11) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.6.11) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.2.8) lib/action_dispatch/middleware/cookies.rb:560:in `call'
  activerecord (4.2.8) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
  actionpack (4.2.8) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.2.8) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
  activesupport (4.2.8) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
  activesupport (4.2.8) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.8) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.2.8) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
  actionpack (4.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.2.8) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.2.8) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.8) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.8) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.8) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.8) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.8) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.2.8) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.6.11) lib/rack/methodoverride.rb:22:in `call'
  rack (1.6.11) lib/rack/runtime.rb:18:in `call'
  activesupport (4.2.8) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  actionpack (4.2.8) lib/action_dispatch/middleware/static.rb:120:in `call'
  rack (1.6.11) lib/rack/sendfile.rb:113:in `call'
  actionpack (4.2.8) lib/action_dispatch/middleware/ssl.rb:24:in `call'
  railties (4.2.8) lib/rails/engine.rb:518:in `call'
  railties (4.2.8) lib/rails/application.rb:165:in `call'
  rack (1.6.11) lib/rack/content_length.rb:15:in `call'
  thin (1.7.2) lib/thin/connection.rb:86:in `block in pre_process'
  thin (1.7.2) lib/thin/connection.rb:84:in `catch'
  thin (1.7.2) lib/thin/connection.rb:84:in `pre_process'
  thin (1.7.2) lib/thin/connection.rb:53:in `process'
  thin (1.7.2) lib/thin/connection.rb:39:in `receive_data'
  eventmachine (1.2.7) lib/eventmachine.rb:195:in `run_machine'
  eventmachine (1.2.7) lib/eventmachine.rb:195:in `run'
  thin (1.7.2) lib/thin/backends/base.rb:73:in `start'
  thin (1.7.2) lib/thin/server.rb:162:in `start'
  rack (1.6.11) lib/rack/handler/thin.rb:19:in `run'
  rack (1.6.11) lib/rack/server.rb:287:in `start'
  railties (4.2.8) lib/rails/commands/server.rb:80:in `start'
  railties (4.2.8) lib/rails/commands/commands_tasks.rb:80:in `block in server'
  railties (4.2.8) lib/rails/commands/commands_tasks.rb:75:in `tap'
  railties (4.2.8) lib/rails/commands/commands_tasks.rb:75:in `server'
  railties (4.2.8) lib/rails/commands/commands_tasks.rb:39:in `run_command!'
  railties (4.2.8) lib/rails/commands.rb:17:in `<top (required)>'
  bin/rails:8:in `require'
  bin/rails:8:in `<main>'

I tried creating a test app with Facebook using localhost and it works. I tried with another app in production with another domain and it works. It does not work with this particular application in production. I messaged Facebook support, but they don't reply, and days have passed.

I'm using RoR 4.2.8, with Bundler 1.17.3 I tried with ruby-2.5.1 and ruby-2.3.3 just in case (same error)

I tried with another Facebook app with identical settings, using another RoR v5 app with ruby-2.6 and it worked, so the FB app settings seem to be ok.

I created another FB app, to try with the failing RoR v4.2.8 app, and it fails with the same "Faraday::ConnectionFailed (execution expired):" error.

config/initializers/omniauth.rb

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, 'APP-ID', 'SECRET',
    scope: 'email'
end

Users should be able lo login using Facebook, but it fails with "Faraday::ConnectionFailed (execution expired):"


Solution

  • From what it looks like is you are having a network issue where Faraday isn't set up to wait long enough for a response. All I can really tell from the trace is that somewhere along the trail to facebook and back you're encountering network issues.

    A couple of things I can think to check:

    • If your site is running through HTTPS, ensure your certificate is working properly.
      • Check that your gemfile is set to require a specific version of omniauth-facebook that is compatible with your version of Rails and dependencies.
      • Extend the timeout length for Faraday
      • Use a retry gem like https://github.com/ooyala/retries to try and give the network enough time to respond before Faraday closes the connection.

    A few other people have commented on this issue in omniauth-facebook's github https://github.com/mkdynamic/omniauth-facebook/issues/283