Merge pull request #30 from ellisonbg/clear-interval

Add clearInterval calls to clean up closure passed to setInterval
This commit is contained in:
Kevin Jahns 2020-10-04 12:18:43 +02:00 committed by GitHub
commit db90e2a594
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -216,9 +216,7 @@ exports.setupWSConnection = (conn, req, { docName = req.url.slice(1).split('?')[
doc.conns.set(conn, new Set())
// listen and reply to events
conn.on('message', /** @param {ArrayBuffer} message */ message => messageListener(conn, doc, new Uint8Array(message)))
conn.on('close', () => {
closeConn(doc, conn)
})
// Check if connection is still alive
let pongReceived = true
const pingInterval = setInterval(() => {
@ -233,12 +231,18 @@ exports.setupWSConnection = (conn, req, { docName = req.url.slice(1).split('?')[
conn.ping()
} catch (e) {
closeConn(doc, conn)
clearInterval(pingInterval)
}
}
}, pingTimeout)
conn.on('close', () => {
closeConn(doc, conn)
clearInterval(pingInterval)
})
conn.on('pong', () => {
pongReceived = true
})
// send sync step 1
const encoder = encoding.createEncoder()
encoding.writeVarUint(encoder, messageSync)