From fa9a4480e619c3d0b969225bbdc2a88e3c6072b6 Mon Sep 17 00:00:00 2001 From: Jacob MacElroy Date: Wed, 30 May 2018 16:32:02 +0000 Subject: [PATCH] Fixing an issue with asnyc http request handlers. The current poltergeist http api immediately returns and does not wait for async work in the handler to finish. This mostly occurs when a public asap key needs to be fetched due to a cache miss. The fix implements the strategy described at https://prosody.im/doc/developers/http.html --- resources/prosody-plugins/util.lib.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/resources/prosody-plugins/util.lib.lua b/resources/prosody-plugins/util.lib.lua index 6f7e26b1e..52600e7a3 100644 --- a/resources/prosody-plugins/util.lib.lua +++ b/resources/prosody-plugins/util.lib.lua @@ -62,15 +62,17 @@ end function wrap_async_run(event,handler) - local result; + -- Grab a local response so that we can send the http response when + -- the handler is done. + local response = event.response; local async_func = runner(function (event) - local wait, done = waiter(); - result=handler(event); - done(); - return result; + response.status_code = handler(event); + -- Send the response to the waiting http client. + response:send(); end) async_func:run(event) - return result; + -- return true to keep the client http connection open. + return true; end --- Updates presence stanza, by adding identity node @@ -136,4 +138,4 @@ return { wrap_async_run = wrap_async_run; room_jid_match_rewrite = room_jid_match_rewrite; update_presence_identity = update_presence_identity; -}; \ No newline at end of file +};