if( exists( $args{timeout} ) ) {
$args{timeout} = int($args{timeout});
- } else {
- $args{timeout} = 10;
+ $self->{recv_timeout} = $args{timeout};
}
#$args{timeout} = 0 if ($self->complete);
$args{count} ||= 1;
my $avail = @{ $self->{recv_queue} };
- my $time_remaining = $args{timeout};
+ $self->{remaining_recv_timeout} = $self->{recv_timeout};
- while ( $avail < $args{count} and $time_remaining > 0 ) {
+ while ( $self->{remaining_recv_timeout} > 0 and $avail < $args{count} ) {
last if $self->complete;
my $starttime = time;
- $self->queue_wait($time_remaining);
+ $self->queue_wait($self->{remaining_recv_timeout});
my $endtime = time;
- $time_remaining -= ($endtime - $starttime);
+ if ($self->{timeout_reset}) {
+ $self->{timeout_reset} = 0;
+ } else {
+ $self->{remaining_recv_timeout} -= ($endtime - $starttime)
+ }
$avail = @{ $self->{recv_queue} };
}
$self->send( 'STATUS', @_ );
}
+sub reset_request_timeout {
+ my $self = shift;
+ my $tt = shift;
+ my $req = $self->app_request($tt);
+ $req->{remaining_recv_timeout} = $req->{recv_timeout};
+ $req->{timout_reset} = 1;
+}
+
#-------------------------------------------------------------------------------
package OpenSRF::AppRequest;
my $threadTrace = $session->session_threadTrace || $session->last_threadTrace;
my $payload = shift;
- my $self = { session => $session,
- threadTrace => $threadTrace,
- payload => $payload,
- complete => 0,
- recv_queue => [],
+ my $self = { session => $session,
+ threadTrace => $threadTrace,
+ payload => $payload,
+ complete => 0,
+ timeout_reset => 0,
+ recv_timeout => 30,
+ remaining_recv_timeout => 30,
+ recv_queue => [],
};
bless $self => $class;
} else {
my $session = OpenSRF::AppSession->create($self->{server_class});
try {
- $session->connect or OpenSRF::EX::WARN->throw("Connection to [$$self{server_class}] timed out");
+ #$session->connect or OpenSRF::EX::WARN->throw("Connection to [$$self{server_class}] timed out");
my $remote_req = $session->request( $self->{api_name}, @params );
while (my $remote_resp = $remote_req->recv) {
OpenSRF::Utils::Logger->debug("Remote Subrequest Received " . $remote_resp, INTERNAL );
$req->respond( $remote_resp->content );
}
$remote_req->finish();
- $session->disconnect();
- $session->finish();
} catch Error with {
my $e = shift;
return undef;
};
+ if ($session) {
+ $session->disconnect();
+ $session->finish();
+ }
+
$log->debug( "Remote Subrequest Responses " . join(" ", $req->responses), INTERNAL );
return $req->responses;
if ($self->payload->statusCode == STATUS_TIMEOUT) {
$session->state( $session->DISCONNECTED );
$session->reset;
+ $session->connect;
$session->push_resend( $session->app_request($self->threadTrace) );
$log->debug("Disconnected because of timeout", WARN);
return 0;
} elsif ($self->payload->statusCode == STATUS_REDIRECTED) {
$session->state( $session->DISCONNECTED );
$session->reset;
+ $session->connect;
$session->push_resend( $session->app_request($self->threadTrace) );
$log->debug("Disconnected because of redirect", WARN);
return 0;
return 0;
} elsif ($self->payload->statusCode == STATUS_CONTINUE) {
+ $session->reset_request_timeout($self->threadTrace);
return 0;
} elsif ($self->payload->statusCode == STATUS_COMPLETE) {