From c051d69509c8593fd877754bda99997d7865daef Mon Sep 17 00:00:00 2001 From: Martin Dosch Date: Sun, 3 Mar 2024 12:10:45 +0100 Subject: [PATCH] Improve closing the stream. --- xmpp.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/xmpp.go b/xmpp.go index 58bc88b..1ea1456 100644 --- a/xmpp.go +++ b/xmpp.go @@ -338,15 +338,18 @@ func (c *Client) Close() error { break default: ee, err := nextEnd(c.p) + // If the server already closed the stream it is + // likely to receive an error when trying to parse + // the stream. Therefore the connection is also closed + // if an error is received. if err != nil { - return err + return c.conn.Close() } if ee.Name.Local == "stream" { return c.conn.Close() } } } - return c.conn.Close() } return nil } @@ -1438,6 +1441,7 @@ func nextStart(p *xml.Decoder) (xml.StartElement, error) { // Scan XML token stream to find next EndElement func nextEnd(p *xml.Decoder) (xml.EndElement, error) { + p.Strict = false for { t, err := p.Token() if err != nil || t == nil {