forked from jshiffer/go-xmpp
Fix timeout when server doesn't reply with closing stream element.
This commit is contained in:
parent
da17a46e6f
commit
aef1257ed1
29
xmpp.go
29
xmpp.go
@ -339,23 +339,22 @@ func NewClientNoTLS(host, user, passwd string, debug bool) (*Client, error) {
|
|||||||
func (c *Client) Close() error {
|
func (c *Client) Close() error {
|
||||||
if c.conn != (*tls.Conn)(nil) {
|
if c.conn != (*tls.Conn)(nil) {
|
||||||
fmt.Fprintf(c.stanzaWriter, "</stream:stream>\n")
|
fmt.Fprintf(c.stanzaWriter, "</stream:stream>\n")
|
||||||
|
go func() {
|
||||||
|
<-time.After(10 * time.Second)
|
||||||
|
c.conn.Close()
|
||||||
|
}()
|
||||||
// Wait for the server also closing the stream.
|
// Wait for the server also closing the stream.
|
||||||
for {
|
for {
|
||||||
select {
|
ee, err := c.nextEnd()
|
||||||
case <-time.After(10 * time.Second):
|
// If the server already closed the stream it is
|
||||||
break
|
// likely to receive an error when trying to parse
|
||||||
default:
|
// the stream. Therefore the connection is also closed
|
||||||
ee, err := c.nextEnd()
|
// if an error is received.
|
||||||
// If the server already closed the stream it is
|
if err != nil {
|
||||||
// likely to receive an error when trying to parse
|
return c.conn.Close()
|
||||||
// the stream. Therefore the connection is also closed
|
}
|
||||||
// if an error is received.
|
if ee.Name.Local == "stream" {
|
||||||
if err != nil {
|
return c.conn.Close()
|
||||||
return c.conn.Close()
|
|
||||||
}
|
|
||||||
if ee.Name.Local == "stream" {
|
|
||||||
return c.conn.Close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user