From b407d5cd1133ccddce57c773f28d0037512e61d5 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 9 Oct 2025 10:18:15 +0100 Subject: [PATCH] xmpp_transport: Add buffer to closeChan to prevent deadlock closeChan is used to communicate that a stream close has been received. In the case where the client initiates the stream closure, this works: 1) client sends stream close 2) client reads from closeChan, waiting for the server's stream close In the case where the server initiates the stream closure, it failed: 1) transport writes to closeChan x) client is not waiting on closeChan, so the write blocks and transport hangs This change allows up to one event to be written asynchronously to closeChan. After the client is notified about the disconnection, it will read from closeChan as in the client-initiated flow but will simply find the stream close already there. --- xmpp_transport.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmpp_transport.go b/xmpp_transport.go index fd53ddb..c7d2022 100644 --- a/xmpp_transport.go +++ b/xmpp_transport.go @@ -43,7 +43,7 @@ func (t *XMPPTransport) Connect() (string, error) { return "", NewConnError(err, true) } - t.closeChan = make(chan stanza.StreamClosePacket) + t.closeChan = make(chan stanza.StreamClosePacket, 1) t.readWriter = newStreamLogger(t.conn, t.logFile) t.decoder = xml.NewDecoder(bufio.NewReaderSize(t.readWriter, maxPacketSize)) t.decoder.CharsetReader = t.Config.CharsetReader