Failed oAuth from clustered website


#1

Hi All,

I’m currently implementing twitter login on my website. I have my own servers and it’s clustered (currently only two and load balanced).
I’m using EpiOauth (https://github.com/jmathai/twitter-async).
The problem is that one of the machine failed when getting oauth_token (getAuthenticateUrl). I am pretty sure that both machine have same code, same settings, same everything except the local IP ofcourse. FYI, the time settings is also ok too.
I tried to stop the cluster and only use one of them (tried both, one by one) and it’s working. But when I tried activate the cluster again, the problem persist.
FYI, the status code is ‘0’. Yes, ‘0’, not ‘401’.
How could this happened? Any suggestions to make all of them working?

Thanks,
Bobby


#2

In most cases where you receive a status code 0, it’s not actually presented to you through any response on Twitter’s side, instead it’s some kind of network error that’s being presented to you as a kind of fake HTTP status code 0. I would walk through the entire request cycles on both machines and try to identify any other differences.


#3

Hey Taylor and elitsertutor,

I’m having this trouble today as well. It’s a bit urgent, as our app http://leapfor.it launches tomorrow.

The issue seems to occur when I make a request from a server that is currently behind a load balancer. If I remove the load balancer, the request works fine.

We’re you able to figure out what was happening on this?

Thank you,
Ryan


#4

The load balancer balances outbound “load” ? Is it possible whatever proxy your requests are sent through aren’t allowing calls to twitter.com or api.twitter.com explicitly or possibly disallowing SSL-bearing connections?


#5

Taylor, thanks so much for the response. I just figured it out. Your suggestion was enough to guide me in the right direction.

The quick solution
Comment out lines 171 and 172 of this file in the Twitter-Async library: https://github.com/jmathai/twitter-async/blob/master/EpiOAuth.php#L171

The reason
The library makes an asynchronous curl to Twitter. The curl is supposed to pass its IP address within that call so Twitter knows where to respond. Since my server sits behind a load balancer, the server was passing an internal IP address in the curl request. Twitter’s response was never making it back to my server because Twitter can’t send to my internal IP Address.

And here’s the full background of the issue I was having

I have an iOS app that talks with my web API. A few of those API calls result in the server making a Twitter status. I have 3 environments dev, stage, and production.

Stage and Production both have load balancers that split traffic across a handful of webservers. Dev does not have a load balancer – it just has 1 webserver.

When an iOS app sends a request to the dev server, the dev server processes the request and makes the appropriate call to Twitter if necessary.

When the iOS app sends a request to the stage or production servers, the entire Exception that is thrown is the appended to the bottom of this message.

If I switch the DNS for the stage environment to skip the load balancer, the Twitter calls work fine from the stage environment.


#6

Just a note that I had the same problem (running on a localhost) and Leap’s suggestion did work.