Skip to content

Commit

Permalink
Merge pull request #274 from hannatao/master
Browse files Browse the repository at this point in the history
bugfix #273: check connectack before create sub
  • Loading branch information
hannatao authored Sep 14, 2021
2 parents ff65f58 + 3754283 commit 81adb85
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 81adb85

Please sign in to comment.