Hi, I am having issue on "read timeout at perl5/Net/HTTP/Methods.pm line 236." for Net::SSL. I don't know if this is server or code related issue. Here is my testing code.
perl -d -e ' use Net::SSL; use LWP::Debug qw(+); use LWP::UserAgent; use HTTP::Headers; use HTTP::Request; $ENV{HTTPS_DEBUG} = 1; $ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0; my $http_read_size_hint = 1 << 20; my $req = HTTP::Request->new('GET', "https://<hostname>/webservices/") +; my $ua = LWP::UserAgent->new(timeout=>5); my $response = $ua->request($req); print $response->as_string(); '
SSL_connect:before/connect initialization SSL_connect:SSLv2/v3 write client hello A SSL_connect:SSLv3 read server hello A SSL_connect:SSLv3 read server certificate A SSL_connect:SSLv3 read server done A SSL_connect:SSLv3 write client key exchange A SSL_connect:SSLv3 write change cipher spec A SSL_connect:SSLv3 write finished A SSL_connect:SSLv3 flush data SSL_connect:SSLv3 read finished A HTTP/1.1 200 OK Cache-Control: private Date: Fri, 13 Dec 2013 05:18:52 GMT Server: Microsoft-IIS/7.0 Content-Length: 2255 Content-Type: text/xml; charset=utf-8 Client-Aborted: die Client-Date: Fri, 13 Dec 2013 05:20:55 GMT Client-Peer: ... Header Removed ... Client-Response-Num: 1 Client-SSL-Cert-Issuer: ... Header Removed ... Client-SSL-Cert-Subject: ... Header Removed ... Client-SSL-Cipher: AES128-SHA Client-SSL-Socket-Class: Net::SSL Client-SSL-Warning: Peer certificate not verified X-AspNet-Version: 4.0.30319 X-Died: read timeout at perl5/Net/HTTP/Methods.pm line 236. <?xml version="1.0" encoding="utf-8"?> <someResponse> <someList> <someItem> ... Some data ... <home
As you can see the data is cutting out in the middle. When I add a break point inside Net::HTTP::Methods. I find that the select() in can_read function is not able to return anything but the sysread() function is able to return data from the buffer. It seems that select() is blocked by somewhere from the system and cannot find the filehandle for 3 minutes. However the filehandle is ready for sysread(). I've attached the debug code in below. Please note that $timeout is 5 seconds
package Net::HTTP::Methods; require 5.005; # 4-arg substr ... sub my_read { die if @_ > 3; my $self = shift; my $len = $_[1]; for (${*$self}{'http_buf'}) { if (length) { $_[0] = substr($_, 0, $len, ""); return length($_[0]); } else { die "read timeout" unless $self->can_read; #Break Point# return $self->sysread($_[0], $len); } } } ... sub can_read { my $self = shift; return 1 unless defined(fileno($self)); return 1 if $self->isa('IO::Socket::SSL') && $self->pending; # With no timeout, wait forever. An explict timeout of 0 can be # used to just check if the socket is readable without waiting. my $timeout = @_ ? shift : (${*$self}{io_socket_timeout} || undef) +; my $fbits = ''; vec($fbits, fileno($self), 1) = 1; SELECT: { my $before; $before = time if $timeout; my $nfound = select($fbits, undef, undef, $timeout); if ($nfound < 0) { if ($!{EINTR} || $!{EAGAIN}) { # don't really think EAGAIN can happen here if ($timeout) { $timeout -= time - $before; $timeout = 0 if $timeout < 0; } redo SELECT; } die "select failed: $!"; } return $nfound > 0; } }
Here is a demonstration on issue: sysread is able to return the buffer from filehandle but select cannot locate the filehandle
main::(-e:8): $ENV{HTTPS_DEBUG} = 1; DB<12> c SSL_connect:before/connect initialization SSL_connect:SSLv2/v3 write client hello A SSL_connect:SSLv3 read server hello A SSL_connect:SSLv3 read server certificate A SSL_connect:SSLv3 read server done A SSL_connect:SSLv3 write client key exchange A SSL_connect:SSLv3 write change cipher spec A SSL_connect:SSLv3 write finished A SSL_connect:SSLv3 flush data SSL_connect:SSLv3 read finished A Net::HTTP::Methods::my_read(/usr/local/share/perl5/Net/HTTP/Methods.pm +:236): 236: die "read timeout" unless $self->can_read; DB<12> print localtime()."\n"; print $self->can_read; print "\n"; pr +int localtime()."\n"; my $text; my $rd = $self->sysread($text, $len); + print $text."\n\nLength: ".$rd; Fri Dec 13 15:45:25 2013 Fri Dec 13 15:45:30 2013 Phone /> ... Some data ... </someItem> </someList> </someResponse> Length: 1449
Here is a demonstration on issue: select cannot locate the filehandle for 3 minutes. Please note that the sysread is ready as shown in above.
main::(-e:8): $ENV{HTTPS_DEBUG} = 1; DB<13> c SSL_connect:before/connect initialization SSL_connect:SSLv2/v3 write client hello A SSL_connect:SSLv3 read server hello A SSL_connect:SSLv3 read server certificate A SSL_connect:SSLv3 read server done A SSL_connect:SSLv3 write client key exchange A SSL_connect:SSLv3 write change cipher spec A SSL_connect:SSLv3 write finished A SSL_connect:SSLv3 flush data SSL_connect:SSLv3 read finished A Net::HTTP::Methods::my_read(/usr/local/share/perl5/Net/HTTP/Methods.pm +:236): 236: die "read timeout" unless $self->can_read; DB<13> print localtime()."\n"; print $self->can_read; print "\n"; pr +int localtime()."\n"; Fri Dec 13 15:48:50 2013 Fri Dec 13 15:48:55 2013 DB<14> print localtime()."\n"; print $self->can_read; print "\n"; pr +int localtime()."\n"; Fri Dec 13 15:50:15 2013 Fri Dec 13 15:50:20 2013 DB<15> print localtime()."\n"; print $self->can_read; print "\n"; pr +int localtime()."\n"; Fri Dec 13 15:51:00 2013 1 Fri Dec 13 15:51:00 2013 DB<16> c HTTP/1.1 200 OK Cache-Control: private Date: Fri, 13 Dec 2013 05:48:39 GMT Server: Microsoft-IIS/7.0 Content-Length: 2255 Content-Type: text/xml; charset=utf-8 Client-Date: Fri, 13 Dec 2013 05:51:19 GMT Client-Peer: ... Header Removed ... Client-Response-Num: 1 Client-SSL-Cert-Issuer: ... Header Removed ... Client-SSL-Cert-Subject: ... Header Removed ... Client-SSL-Cipher: AES128-SHA Client-SSL-Socket-Class: Net::SSL Client-SSL-Warning: Peer certificate not verified WebFarmServer: WEB2 X-AspNet-Version: 4.0.30319 <?xml version="1.0" encoding="utf-8"?> <someResponse> <someList> <someItem> ... Some Data ... <homePhone /> ... Some Data ... </someItem> </someList> </someResponse>
Currently, we are commenting out the following line to allow SSL requests. However, this will create sysread timeout issues will may lock the system for a longer time. We cannot use a loop to check can_read call as this will take 3 minutes for every SSL requests.
#die "read timeout" unless $self->can_read;
Please give me ideas on how to fix this issue. Thank you.

In reply to LWP::UserAgent Net::SSL read timeout issue by salmon739

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.