Skip to content

Commit

Permalink
fix: safer subscribe (#372)
Browse files Browse the repository at this point in the history
Fixes #361
  • Loading branch information
robertsLando authored Jan 27, 2021
1 parent 5809a03 commit e113d76
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/MqttClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ function onConnect () {
this.emit('connect')

if (this.toSubscribe) {
for (let i = 0; i < this.toSubscribe.length; i++) {
this.subscribe(this.toSubscribe[i])
// don't use toSubscribe here to prevent infinite loops when subscribe fails
const topics = [...this.toSubscribe]
for (const t of topics) {
this.subscribe(t)
}
}

Expand Down

0 comments on commit e113d76

Please sign in to comment.