Skip to content

Commit 81adb85

Browse files
authored
Merge pull request #274 from hannatao/master
bugfix #273: check connectack before create sub
2 parents ff65f58 + 3754283 commit 81adb85

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

mqtt/stream.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,6 @@ func (c *Client) connect(obs Observer) (s *stream, err error) {
4747
return nil, errors.Trace(err)
4848
}
4949

50-
if len(c.ops.Subscriptions) != 0 {
51-
subscribe := NewSubscribe()
52-
subscribe.ID = subscribeId
53-
subscribe.Subscriptions = c.ops.Subscriptions
54-
err = conn.Send(subscribe, false)
55-
if err != nil {
56-
conn.Close()
57-
return nil, errors.Trace(err)
58-
}
59-
}
60-
6150
s = &stream{
6251
cli: c,
6352
observer: obs,
@@ -76,6 +65,14 @@ func (c *Client) connect(obs Observer) (s *stream, err error) {
7665
return nil, errors.Trace(err)
7766
}
7867
if len(c.ops.Subscriptions) != 0 {
68+
subscribe := NewSubscribe()
69+
subscribe.ID = subscribeId
70+
subscribe.Subscriptions = c.ops.Subscriptions
71+
err = conn.Send(subscribe, false)
72+
if err != nil {
73+
conn.Close()
74+
return nil, errors.Trace(err)
75+
}
7976
err = s.subscribeFuture.Wait(c.ops.Timeout)
8077
if err != nil {
8178
s.die("subscribe timeout", err)

0 commit comments

Comments
 (0)