Skip to content

Commit

Permalink
bugfix #273: check connectack before create sub
Browse files Browse the repository at this point in the history
  • Loading branch information
hanpengfei01 committed Sep 13, 2021
1 parent 9c338a1 commit 3754283
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions mqtt/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,6 @@ func (c *Client) connect(obs Observer) (s *stream, err error) {
return nil, errors.Trace(err)
}

if len(c.ops.Subscriptions) != 0 {
subscribe := NewSubscribe()
subscribe.ID = subscribeId
subscribe.Subscriptions = c.ops.Subscriptions
err = conn.Send(subscribe, false)
if err != nil {
conn.Close()
return nil, errors.Trace(err)
}
}

s = &stream{
cli: c,
observer: obs,
Expand All @@ -76,6 +65,14 @@ func (c *Client) connect(obs Observer) (s *stream, err error) {
return nil, errors.Trace(err)
}
if len(c.ops.Subscriptions) != 0 {
subscribe := NewSubscribe()
subscribe.ID = subscribeId
subscribe.Subscriptions = c.ops.Subscriptions
err = conn.Send(subscribe, false)
if err != nil {
conn.Close()
return nil, errors.Trace(err)
}
err = s.subscribeFuture.Wait(c.ops.Timeout)
if err != nil {
s.die("subscribe timeout", err)
Expand Down

0 comments on commit 3754283

Please sign in to comment.