Faraday net_http_persistent not working in Phusion Passenger

Skip to first unread message

Jack Ocampo

Apr 3, 2019, 12:58:30 PM4/3/19
to Philippine Ruby Users Group (PRUG/PhRUG)
Basic info:
  • Faraday Version: 0.15.4
  • Ruby Version: 2.5.0
  • Passenger: 6.0.2
Issue description:
Good day mga ka Ruby guys,

I have a rails app with api endpoint that will authenticate to the remote server by using api_key in order to authorized the current user.
This endpoint is using Faraday to connect to the remote server. See example below:
      'X-Version' => 'V1',
      'X-API-Key' => 123456,
      'Content-Type' =>'application/json'
uri = "https://api.remoteserver.com/VerifyAPIKey"
conn = Faraday.new() do |f|
   f.adapter :net_http_persistent do |http|  
   http.idle_timeout = 100
@response = conn.post do |req|
  req.url URI(uri)
  req.headers = HEADERS
  req.body = body

If you notice, I configure the adapter of Faraday using net_http_persistent because I'm running an open-source Phusion Passenger server and we need a persistent connection because the Passenger is a multi-process which means it will spawn one or more processes as the load increases. However at first request the api was successfully authorized(see processID #26698) but on the next request I got authorization error (processID #64121)
See the logs below:
I, [2019-04-01T18:20:29.611996 #26698] INFO -- Authorization is finished successfully.
I, [2019-04-01T18:20:29.611996 #26698] INFO Thread with name "MsgsQueue worker #47338607938600"
I, [2019-04-01T18:20:29.611996 #26698] INFO Thread with name "MsgsQueue worker #47338625106140"
I, [2019-04-01T23:20:09.341415 #64121] INFO Authorization error. Need to authenticate first!
I, [2019-04-01T23:20:09.341415 #64121] INFO Thread with name "LogsSender worker #47158391867980" is terminated!
I, [2019-04-01T23:20:09.341415 #64121] INFO Thread with name "LogsSender worker #42158391867991" is terminated!

Is there any settings in Faraday that I'm missing ?
Any help would be greatly appreciated. Thanks

Ramon Tayag

Apr 3, 2019, 10:19:48 PM4/3/19
to Philippine Ruby Users Group
Your Rails app is the one you're trying to authenticate with? Or your Rails app makes a call to another Rails app with Phusion?

Try making this call with something like Postman or just plain curl first.

Ramon Tayag

You received this message because you are subscribed to the Google Groups "Philippine Ruby Users Group (PRUG/PhRUG)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-phil+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
0 new messages