Further reduce possible data races.

This commit is contained in:
Martin Dosch 2024-04-02 13:39:45 +02:00
parent ce687243c1
commit 0ae62a33a2

View File

@ -1563,6 +1563,11 @@ func (c *Client) nextEnd() (xml.EndElement, error) {
t := xml.CopyToken(to) t := xml.CopyToken(to)
switch t := t.(type) { switch t := t.(type) {
case xml.EndElement: 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() c.nextMutex.Unlock()
return t, nil return t, nil
} }
@ -1623,9 +1628,11 @@ func (c *Client) next() (xml.Name, interface{}, error) {
} }
// Unmarshal into that storage. // Unmarshal into that storage.
c.nextMutex.Lock()
if err = c.p.DecodeElement(nv, &se); err != nil { if err = c.p.DecodeElement(nv, &se); err != nil {
return xml.Name{}, nil, err return xml.Name{}, nil, err
} }
c.nextMutex.Unlock()
return se.Name, nv, err return se.Name, nv, err
} }