diff --git a/client.go b/client.go index 817e664e..af5538e6 100644 --- a/client.go +++ b/client.go @@ -799,12 +799,10 @@ func (c *client) Publish(topic string, qos byte, retained bool, payload interfac if publishWaitTimeout == 0 { publishWaitTimeout = time.Second * 30 } + t := time.NewTimer(publishWaitTimeout) - defer func() { - if !t.Stop() { - <-t.C - } - }() + defer t.Stop() + select { case c.obound <- &PacketAndToken{p: pub, t: token}: case <-t.C: