Bladeren bron

Fix call after timeout

j8
Andrei Bora 4 jaren geleden
bovenliggende
commit
af71d80150
1 gewijzigde bestanden met toevoegingen van 15 en 11 verwijderingen
  1. 15
    11
      resources/prosody-plugins/util.lib.lua

+ 15
- 11
resources/prosody-plugins/util.lib.lua Bestand weergeven

@@ -225,17 +225,22 @@ end
225 225
 -- the external call failed after the last retry
226 226
 function http_get_with_retry(url, retry)
227 227
     local content, code;
228
+    local timeout_occurred;
228 229
     local wait, done = async.waiter();
229 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 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 243
         end
238
-        done();
239 244
     end
240 245
 
241 246
     local function call_http()
@@ -251,6 +256,8 @@ function http_get_with_retry(url, retry)
251 256
         -- TODO: This check is racey. Not likely to be a problem, but we should
252 257
         --       still stick a mutex on content / code at some point.
253 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 261
             -- no longer present in prosody 0.11, so check before calling
255 262
             if http.destroy_request ~= nil then
256 263
                 http.destroy_request(request);
@@ -272,10 +279,7 @@ function http_get_with_retry(url, retry)
272 279
     timer.add_task(http_timeout, cancel);
273 280
     wait();
274 281
 
275
-    if code == 200 or code == 204 then
276
-        return content;
277
-    end
278
-    return nil;
282
+    return content;
279 283
 end
280 284
 
281 285
 return {

Laden…
Annuleren
Opslaan