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
9
xmpp.go
9
xmpp.go
@ -339,12 +339,12 @@ 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 {
|
|
||||||
case <-time.After(10 * time.Second):
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
ee, err := c.nextEnd()
|
ee, err := c.nextEnd()
|
||||||
// If the server already closed the stream it is
|
// If the server already closed the stream it is
|
||||||
// likely to receive an error when trying to parse
|
// likely to receive an error when trying to parse
|
||||||
@ -358,7 +358,6 @@ func (c *Client) Close() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user