MT#13269 Make timeout for the remote server access

To don't stack in connection attempt and don't get "mysql has gone" error

Change-Id: Ida9434179ff75090280e300f7782c60aaf6ae2f5
changes/95/1895/12
Irina Peshinskaya 10 years ago
parent 7ba2dbd0d3
commit d0b947ccf5

@ -57,16 +57,28 @@ sub rpc_https_call{
my $c = $self->params->{c};
$c->log->debug( "rpc_https_call: host=$cfg->{host}; port=$cfg->{port}; path=$cfg->{path}; content=$content;" );
#$c->log->debug( Dumper($cfg->{headers}) );
my( $page, $response_code, %reply_headers ) = https_post({
'host' => $cfg->{host},
'port' => $cfg->{port},
'path' => $cfg->{path},
'headers' => $cfg->{headers},
'Content-Type' => 'text/xml',
'content' => $content,
},);
$c->log->info( "rpc_https_call: response=$response_code; page=$page;" );
my $response_value = '';
my( $page, $response_code, %reply_headers, $response_value );
eval {
local $SIG{ALRM} = sub { die "Connection timeout\n" };
alarm(25);
( $page, $response_code, %reply_headers ) = https_post({
'host' => $cfg->{host},
'port' => $cfg->{port},
'path' => $cfg->{path},
'headers' => $cfg->{headers},
'Content-Type' => 'text/xml',
'content' => $content,
},);
alarm(0);
};
alarm(0);
if ($@ && !$page) {
$c->log->debug( "eval error: $@;" );
if ($@ =~ /Connection timeout/) {
$response_value = 'Connection timeout';
}
}
$c->log->info( "response=$response_code; page=$page;" );
if($page){
my $rpc_response = $self->parse_rpc_response_page($page);
$response_value = $self->parse_rpc_response($rpc_response);

@ -0,0 +1,81 @@
#!/usr/bin/perl
use strict;
use MIME::Base64 qw/encode_base64/;
use URI::Escape;
use Data::Dumper;
use Net::HTTPS::Any qw/https_post/;
my $cfg = {
proto => 'https',
host => 'www.google.com',
port => '81',
#host => 'rps.yealink.com',
#port => '443',
path => '/xmlrpc',
user => '',
password => '',
};
test_timeout();
sub test_timeout {
my $authorization = encode_base64(join(':',@$cfg{qw/user password/}));
$authorization =~s/[ \s]//gis;
$authorization .= '=';
print "authorization=$authorization;\n";
$cfg->{headers} = { 'Authorization' => 'Basic '.$authorization };
my ( $page, $response_code, %reply_headers );
eval {
local $SIG{ALRM} = sub { die "Connection timeout\n" };
alarm(10);
#eval {
( $page, $response_code, %reply_headers ) = https_post({
'host' => $cfg->{host},
'port' => $cfg->{port},
'path' => $cfg->{path},
'headers' => $cfg->{headers},
'Content-Type' => 'text/xml',
'content' => "<?xml version='1.0' encoding='UTF-8'?>
<methodCall>
<methodName>redirect.registerDevice</methodName>
<params>
<param>
<value><string>"."0080f0d4dbf1"."</string></value>
</param>
<param>
<value><string><![CDATA["."0080f0d4dbf10080f0d4"."]]></string></value>
</param>
</params>
</methodCall>",
},);
#if ( $page ) {
# print "qqq;\n";
#} else {
# die "timeout;\n";
#}
#};
print "1.\@=$@;\n";
print Dumper [$page, $response_code, \%reply_headers];
alarm(0);
if ($@) {
print "2.\@=$@;\n";
#if ($@ =~ /SSL timeout/) {
# warn "request timed out";
#} else {
# die "error in request: $@";
#}
}
};
alarm(0);
print "3.\@=$@;\n";
if ($@) {
print "4.\@=$@;\n";
#if ($@ =~ /SSL timeout/) {
# warn "request timed out";
#} else {
# die "error in request: $@";
#}
}
}
Loading…
Cancel
Save