From 51ce661f8d9668b572dc2efb8a62484d37b53f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sch=C3=A4fer?= Date: Sat, 3 May 2025 17:35:09 +0200 Subject: [PATCH] tokio-xmpp: do not discard XmlLangStack when boxing the stream MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The stream may have read some data already (such as the stream header). When initially writing this code, I had missed that we do actually also carry the parser state over: I misread the AsyncReader::wrap(..) command as something like AsyncReader::new, i.e. starting off with fresh parser state, so I assumed that we need a fresh XmlLangStack, too. This is wrong: `p` comes from `self.parser.into_inner()` above and is the parser state, so we need to carry the lang stack along, as well. This fixes: ``` thread 'tokio-runtime-worker' panicked at […]/rxml-0.13.1/src/xml_lang.rs:87:13: pop from empty XmlLangStack ``` happening during stream shutdown. The panic was first reported by @ppjet6, so thanks for that and the keen eye. skip-changelog, because the bug has not been released yet. --- tokio-xmpp/src/xmlstream/common.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tokio-xmpp/src/xmlstream/common.rs b/tokio-xmpp/src/xmlstream/common.rs index 607473466e48c039d934de2fe81554d565ff77fe..1509a36832773c41aa4441750196ab04d7f2c6e2 100644 --- a/tokio-xmpp/src/xmlstream/common.rs +++ b/tokio-xmpp/src/xmlstream/common.rs @@ -300,7 +300,7 @@ impl RawXmlStream { let parser = rxml::AsyncReader::wrap(io, p); RawXmlStream { parser, - lang_stack: XmlLangStack::new(), + lang_stack: self.lang_stack, timeouts: self.timeouts, writer: self.writer, tx_buffer: self.tx_buffer,