# HG changeset patch
# User Kim Alvefur <zash@zash.se>
# Date 1654991433 -7200
# Node ID 3729a6bdb5624d32e7183d51c24d11c407c9a6f0
# Parent  cf29bdb74c151a01467c7775e5ae5d0860dc5370
mod_smacks: Fix #1761 by setting a flag earlier

This ensures that the flag is set even if the pre-drain callback is
called from send(), as would be the case if opportunistic writes are
enabled.

diff -r cf29bdb74c15 -r 3729a6bdb562 plugins/mod_smacks.lua
--- a/plugins/mod_smacks.lua	Thu Jun 09 12:42:57 2022 +0100
+++ b/plugins/mod_smacks.lua	Sun Jun 12 01:50:33 2022 +0200
@@ -156,9 +156,9 @@
 local function request_ack(session, reason)
 	local queue = session.outgoing_stanza_queue;
 	session.log("debug", "Sending <r> (inside timer, before send) from %s - #queue=%d", reason, queue:count_unacked());
+	session.awaiting_ack = true;
 	(session.sends2s or session.send)(st.stanza("r", { xmlns = session.smacks }))
 	if session.destroyed then return end -- sending something can trigger destruction
-	session.awaiting_ack = true;
 	-- expected_h could be lower than this expression e.g. more stanzas added to the queue meanwhile)
 	session.last_requested_h = queue:count_acked() + queue:count_unacked();
 	session.log("debug", "Sending <r> (inside timer, after send) from %s - #queue=%d", reason, queue:count_unacked());