Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Memory leak on client.js 'connected' event #348 #362

Merged
merged 17 commits into from
Jan 28, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ function Client (broker, conn, req) {

this.connDetails = null
robertsLando marked this conversation as resolved.
Show resolved Hide resolved

// queue packets received before client fires 'connect' event. Prevents memory leaks on 'connect' event
this.parser._queue = []

this.on('connected', () => {
robertsLando marked this conversation as resolved.
Show resolved Hide resolved
while (this.parser._queue.length > 0) {
handle(this, this.parser._queue.shift(), this._nextBatch)
}
robertsLando marked this conversation as resolved.
Show resolved Hide resolved
})
robertsLando marked this conversation as resolved.
Show resolved Hide resolved

this.parser.on('packet', enqueue)

function nextBatch (err) {
Expand Down Expand Up @@ -330,9 +339,7 @@ function enqueue (packet) {
if (client.connackSent || client._parsingBatch === 1) {
handle(client, packet, client._nextBatch)
} else {
client.on('connected', () => {
handle(client, packet, client._nextBatch)
})
this._queue.push(packet)
}
}

Expand Down