client: Fix timeout handling

Thu, 23 Mar 2023 12:14:53 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Thu, 23 Mar 2023 12:14:53 +0000
changeset 172
2c17151ed21b
parent 171
433a1f36d0d3
child 173
14ed4cb241f4

client: Fix timeout handling

Previously, the timeout handler would fire an error that would get caught and
logged by the timer code. However that error never reached the upper levels of
scansion, leading to the whole thing just hanging.

Now we just trigger resumption of the async runner, and throw the error from
there if we haven't received the stanza yet.

With this change, timeouts are now correctly handled and reported as failures.

scansion/objects/client.lua file | annotate | diff | comparison | revisions
--- a/scansion/objects/client.lua	Thu Mar 23 11:51:31 2023 +0000
+++ b/scansion/objects/client.lua	Thu Mar 23 12:14:53 2023 +0000
@@ -107,7 +107,12 @@
 		end
 		client.stream:hook("stanza", stanza_handler, 100);
 		verse.add_task(client.stanza_timeout or default_stanza_timeout, function ()
-			if have_received_stanza then return; end
+			done();
+		end);
+		client.stream.conn:resume();
+		wait();
+
+		if not have_received_stanza then
 			if expected_stanza then
 				client.log("TIMEOUT waiting for %s", expected_stanza)
 				local e = new_error("stanza-timeout", { text = "Timed out waiting for stanza" });
@@ -117,9 +122,7 @@
 				client.log("Good - no stanzas were received (expected)");
 				done();
 			end
-		end);
-		client.stream.conn:resume();
-		wait();
+		end
 	end;
 
 	disconnects = function (client)

mercurial