From f98b9b66a0046bb575fa2b5746b577bda5ddeed3 Mon Sep 17 00:00:00 2001 From: blindman2k Date: Mon, 5 Oct 2015 16:55:58 +1100 Subject: [PATCH] Update httpretry.agent.nut New requests where forcing dequeue() even while in back-off phase. Cancel wasn't pulling the requests out of the queue. --- utility/httpplus/httpretry.agent.nut | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/utility/httpplus/httpretry.agent.nut b/utility/httpplus/httpretry.agent.nut index e06cacd..36d0bbd 100644 --- a/utility/httpplus/httpretry.agent.nut +++ b/utility/httpplus/httpretry.agent.nut @@ -60,17 +60,31 @@ class HTTPRetry { local item = _queue[0]; _processing = true; item.requestobj._sendasyncqueued(function(success, result, retry_delay=0) { - _processing = false; if (success) { + _processing = false; _queue.remove(0); item.callback(result); return _dequeue(); } else { - imp.wakeup(retry_delay, _dequeue.bindenv(this)); + imp.wakeup(retry_delay, function() { + _processing = false; + _dequeue(); + }.bindenv(this)); } }.bindenv(this)); } } + + function _remove(requestobj) { + foreach (k,v in _queue) { + if (v.requestobj == requestobj) { + _queue.remove(k); + return k; + } + } + return null; + } + } @@ -120,8 +134,10 @@ class HTTPRetryRequest { if (result.statuscode == 429 && "x-agent-rate-limited" in result.headers && "retry-after" in result.headers) { // This is a retryable failure, wait for as long as are told then try again server.error("Too many outbound HTTP requests. We have been throttled.") - imp.sleep(result.headers["retry-after"].tofloat()); - sendasync(oncomplete, longpolldata, longpolltimeout); + _retry = imp.wakeup(result.headers["retry-after"].tofloat(), function() { + _retry = null; + sendasync(oncomplete, longpolldata, longpolltimeout); + }.bindenv(this); } else { // This is a success or a reportable failure oncomplete(result); @@ -154,6 +170,9 @@ class HTTPRetryRequest { // Cancel the http request _httprequest.cancel(); _httprequest = null; + } else { + // Pull it out of the queue + _parent._remove(this); } }