Skip to content

Commit 6e84084

Browse files
author
rcorniere
committed
Close keepalive when recv() ends in client.go
1 parent 64e5413 commit 6e84084

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,13 @@ func (c *Client) sendWithWriter(writer io.Writer, packet []byte) error {
379379

380380
// Loop: Receive data from server
381381
func (c *Client) recv(keepaliveQuit chan<- struct{}) {
382+
defer func() {
383+
close(keepaliveQuit)
384+
}()
382385
for {
383386
val, err := stanza.NextPacket(c.transport.GetDecoder())
384387
if err != nil {
385388
c.ErrorHandler(err)
386-
close(keepaliveQuit)
387389
c.disconnected(c.Session.SMState)
388390
return
389391
}
@@ -392,7 +394,6 @@ func (c *Client) recv(keepaliveQuit chan<- struct{}) {
392394
switch packet := val.(type) {
393395
case stanza.StreamError:
394396
c.router.route(c, val)
395-
close(keepaliveQuit)
396397
c.streamError(packet.Error.Local, packet.Text)
397398
c.ErrorHandler(errors.New("stream error: " + packet.Error.Local))
398399
// We don't return here, because we want to wait for the stream close tag from the server, or timeout.

0 commit comments

Comments
 (0)