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.
This commit is contained in:
Matthew Wild
2025-10-09 10:18:15 +01:00
committed by Mickaël Rémond
parent 7df984516d
commit b407d5cd11
+1 -1
View File
@@ -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