Skip to content

Commit 4ed6904

Browse files
committed
improve the timeout management, there was an issue when timeout was already set
1 parent 0a721e7 commit 4ed6904

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/Dancer/Plugin/TimeoutManager.pm

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,19 @@ sub timeout {
7272
my $response;
7373

7474
#if timeout is not defined but a value is set in the headers for timeout
75-
$timeout = vars->{header_timeout} if (!defined $timeout && defined vars->{header_timeout});
75+
my $request_timeout = 0;
76+
$request_timeout = $timeout if (defined $timeout);
77+
$request_timeout = vars->{header_timeout} if (!defined $timeout && defined vars->{header_timeout});
7678

7779
# if timeout is not defined or equal 0 the timeout manager is not used
7880
my $timeout_exception;
79-
if (!$timeout){
81+
if (!$request_timeout){
8082
$response = $code->();
8183
}
8284
else{
8385
try {
8486
local $SIG{ALRM} = sub { croak ($exception_message); };
85-
alarm($timeout);
87+
alarm($request_timeout);
8688

8789
$response = $code->();
8890
alarm(0);
@@ -96,7 +98,7 @@ sub timeout {
9698
if ($timeout_exception && $timeout_exception =~ /$exception_message/){
9799
my $response_with_timeout = Dancer::Response->new(
98100
status => 408,
99-
content => "Request Timeout : more than $timeout seconds elapsed."
101+
content => "Request Timeout : more than $request_timeout seconds elapsed."
100102
);
101103
return $response_with_timeout;
102104
}

0 commit comments

Comments
 (0)