I’m writing Web Service using perl 5.16.2, OAuth::Lite(1.31).
Server is CentOS release 6.3 (Final), 2.6.32-279.14.1.el6.x86_64.
Problem is when I request a token for twitter oauth, OAuth::Lite get_request_token blocks server execution for 30 sec, and sometimes returns proper response and sometimes timeouts browser request.
Minimum code to reproduce the probrem is below,
use OAuth::Lite::Consumer;
my $consumer = OAuth::Lite::Consumer->new(
request_token_path => 'https://api.twitter.com/oauth/request_token',
consumer_key => '[CONSUMER KEY]',
consumer_secret => '[CONSUMER SECRET]',
callback_url => '[CALLBACK]',
);
my $rtoken = $consumer->get_request_token();
will return after 30sec.
I read the code, and I figure out that method my_readline in Net::HTTP::Methods line 259-260 in Net::HTTP 6.05
die "read timeout" unless $self->can_read;
my $n = $self->sysread($_, 1024, length);
blocks request. And the header that my_readline trying to read is
HTTP/1.1 200 OK
Date: Fri, 16 Nov 2012 16:16:39 GMT
Status: 200 OK
X-MID: 266cca0268c8eb68e76eedda256c77829ea9b22e
X-Transaction: 784ff126dfead993
Tag: "382e5356bb65e976f6b117bacdfa05e4"
Cache-Control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
X-Runtime: 0.02892
Pragma: no-cache
Expires: Tue, 31 Mar 1981 05:00:00 GMT
X-Frame-Options: SAMEORIGIN
Content-Type: text/html; charset=utf-8
Last-Modified: Fri, 16 Nov 2012 16:16:39 GMT
Set-Cookie: k=10.36.55.109.1353082599368934; path=/; expires=Fri, 23-Nov-12 16:16:39 GMT; domain=.twitter.com
Set-Cookie: guest_id=v1%3A135308259937793094; domain=.twitter.com; path=/; expires=Mon, 17-Nov-2014 04:16:39 GMT
Set-Cookie: _twitter_sess=BAh7CCIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjoKQHVzZWR7ADoHaWQiJTJlZGJiN2MyOTMyNmM0OGY0MjJmZmY0%250AMTU3YzllYTI0Og9jcmVhdGVkX2F0bCsI0vcBCjsB--21ab24a6dd6596b1dcc78651c0b6a4836b320621; domain=.twitter.com; path=/; HttpOnly
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 150
Server: tfe
This header exceeded 1024 characters. So I changed 1024 to 2048, It started to work fine…
I want to figure out the reason of this problem.
Any helps appreciated.
Thanks.
Years ago, I had a bad experience with LWP::Protocol::https (also used by OAuth::Lite), specially on CentOS. To get the long story short: too much frustration trying to compile Net::SSLeay on that platform lead me to replace LWP::UserAgent by WWW::Curl. Which compiles just fine. And worked great for that simple application.
However, OAuth::Lite is tightly coupled to LWP, and it is pointless to reimplement everything.
And there is another way of using libcurl with LWP-based code:
http://blogs.perl.org/users/stas/2012/11/libcurl-as-lwp-backend-or-all-your-protocol-are-belong-to-us.html