Fix call after timeout

This commit is contained in:
Andrei Bora 2020-08-19 17:38:40 +03:00
parent b765adca75
commit af71d80150
1 changed files with 15 additions and 11 deletions

View File

@ -225,8 +225,10 @@ end
-- the external call failed after the last retry -- the external call failed after the last retry
function http_get_with_retry(url, retry) function http_get_with_retry(url, retry)
local content, code; local content, code;
local timeout_occurred;
local wait, done = async.waiter(); local wait, done = async.waiter();
local function cb(content_, code_, response_, request_) local function cb(content_, code_, response_, request_)
if timeout_occurred == nil then
code = code_; code = code_;
if code == 200 or code == 204 then if code == 200 or code == 204 then
module:log("debug", "External call was successful, content %s", content_); module:log("debug", "External call was successful, content %s", content_);
@ -236,6 +238,9 @@ function http_get_with_retry(url, retry)
code_, content_); code_, content_);
end end
done(); done();
else
module:log("warn", "External call reply delivered after timeout from: %s", url);
end
end end
local function call_http() local function call_http()
@ -251,6 +256,8 @@ function http_get_with_retry(url, retry)
-- TODO: This check is racey. Not likely to be a problem, but we should -- TODO: This check is racey. Not likely to be a problem, but we should
-- still stick a mutex on content / code at some point. -- still stick a mutex on content / code at some point.
if code == nil then if code == nil then
timeout_occurred = true;
module:log("warn", "Timeout %s seconds making the external call to: %s", http_timeout, url);
-- no longer present in prosody 0.11, so check before calling -- no longer present in prosody 0.11, so check before calling
if http.destroy_request ~= nil then if http.destroy_request ~= nil then
http.destroy_request(request); http.destroy_request(request);
@ -272,10 +279,7 @@ function http_get_with_retry(url, retry)
timer.add_task(http_timeout, cancel); timer.add_task(http_timeout, cancel);
wait(); wait();
if code == 200 or code == 204 then
return content; return content;
end
return nil;
end end
return { return {