Fix potential resource leaks in streaming server

This commit is contained in:
Eugen Rochko 2017-02-02 15:20:31 +01:00
parent 1ee4a17f37
commit b6c922f169
1 changed files with 8 additions and 3 deletions

View File

@ -45,7 +45,7 @@ const authenticationMiddleware = (req, res, next) => {
return next(err) return next(err)
} }
client.query('SELECT oauth_access_tokens.resource_owner_id, users.account_id FROM oauth_access_tokens INNER JOIN users ON oauth_access_tokens.resource_owner_id = users.id WHERE token = $1 LIMIT 1', [token], (err, result) => { client.query('SELECT oauth_access_tokens.resource_owner_id, users.account_id FROM oauth_access_tokens INNER JOIN users ON oauth_access_tokens.resource_owner_id = users.id WHERE oauth_access_tokens.token = $1 LIMIT 1', [token], (err, result) => {
done() done()
if (err) { if (err) {
@ -115,8 +115,13 @@ const streamFrom = (id, req, res, needsFiltering = false) => {
} }
}) })
// Heartbeat to keep connection alive const heartbeat = setInterval(() => res.write(':thump\n'), 15000)
setInterval(() => res.write(':thump\n'), 15000)
req.on('close', () => {
log.verbose(`Ending stream from ${id} for ${req.accountId}`)
clearInterval(heartbeat)
redisClient.quit()
})
redisClient.subscribe(id) redisClient.subscribe(id)
} }