From 0ae62a33a21ddc2161aa214c88c664f479ff77f3 Mon Sep 17 00:00:00 2001 From: Martin Dosch Date: Tue, 2 Apr 2024 13:39:45 +0200 Subject: [PATCH] Further reduce possible data races. --- xmpp.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/xmpp.go b/xmpp.go index 920b04e..81443b7 100644 --- a/xmpp.go +++ b/xmpp.go @@ -1563,6 +1563,11 @@ func (c *Client) nextEnd() (xml.EndElement, error) { t := xml.CopyToken(to) switch t := t.(type) { case xml.EndElement: + // Do not unlock mutex if the stream is closed to + // prevent further reading on the stream. + if t.Name.Local == "stream" { + return t, nil + } c.nextMutex.Unlock() return t, nil } @@ -1623,9 +1628,11 @@ func (c *Client) next() (xml.Name, interface{}, error) { } // Unmarshal into that storage. + c.nextMutex.Lock() if err = c.p.DecodeElement(nv, &se); err != nil { return xml.Name{}, nil, err } + c.nextMutex.Unlock() return se.Name, nv, err }