浏览代码

Fix call after timeout

master
Andrei Bora 5 年前
父节点
当前提交
af71d80150
共有 1 个文件被更改,包括 15 次插入11 次删除
  1. 15
    11
      resources/prosody-plugins/util.lib.lua

+ 15
- 11
resources/prosody-plugins/util.lib.lua 查看文件

225
 -- the external call failed after the last retry
225
 -- the external call failed after the last retry
226
 function http_get_with_retry(url, retry)
226
 function http_get_with_retry(url, retry)
227
     local content, code;
227
     local content, code;
228
+    local timeout_occurred;
228
     local wait, done = async.waiter();
229
     local wait, done = async.waiter();
229
     local function cb(content_, code_, response_, request_)
230
     local function cb(content_, code_, response_, request_)
230
-        code = code_;
231
-        if code == 200 or code == 204 then
232
-            module:log("debug", "External call was successful, content %s", content_);
233
-            content = content_
231
+        if timeout_occurred == nil then
232
+            code = code_;
233
+            if code == 200 or code == 204 then
234
+                module:log("debug", "External call was successful, content %s", content_);
235
+                content = content_
236
+            else
237
+                module:log("warn", "Error on public key request: Code %s, Content %s",
238
+                    code_, content_);
239
+            end
240
+            done();
234
         else
241
         else
235
-            module:log("warn", "Error on public key request: Code %s, Content %s",
236
-                code_, content_);
242
+            module:log("warn", "External call reply delivered after timeout from: %s", url);
237
         end
243
         end
238
-        done();
239
     end
244
     end
240
 
245
 
241
     local function call_http()
246
     local function call_http()
251
         -- TODO: This check is racey. Not likely to be a problem, but we should
256
         -- TODO: This check is racey. Not likely to be a problem, but we should
252
         --       still stick a mutex on content / code at some point.
257
         --       still stick a mutex on content / code at some point.
253
         if code == nil then
258
         if code == nil then
259
+            timeout_occurred = true;
260
+            module:log("warn", "Timeout %s seconds making the external call to: %s", http_timeout, url);
254
             -- no longer present in prosody 0.11, so check before calling
261
             -- no longer present in prosody 0.11, so check before calling
255
             if http.destroy_request ~= nil then
262
             if http.destroy_request ~= nil then
256
                 http.destroy_request(request);
263
                 http.destroy_request(request);
272
     timer.add_task(http_timeout, cancel);
279
     timer.add_task(http_timeout, cancel);
273
     wait();
280
     wait();
274
 
281
 
275
-    if code == 200 or code == 204 then
276
-        return content;
277
-    end
278
-    return nil;
282
+    return content;
279
 end
283
 end
280
 
284
 
281
 return {
285
 return {

正在加载...
取消
保存