diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2017-02-02 15:20:31 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-02-02 15:20:31 +0100 |
commit | b6c922f169b6ec76d6e55336ac8a76e4f3e3843a (patch) | |
tree | ad4d861d060da8f8e575e71fcb43d3e5028efca5 /streaming/index.js | |
parent | 1ee4a17f3792669d3f03ddcb060aa48b622eca61 (diff) |
Fix potential resource leaks in streaming server
Diffstat (limited to 'streaming/index.js')
-rw-r--r-- | streaming/index.js | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/streaming/index.js b/streaming/index.js index 945e287f5..99aa5b040 100644 --- a/streaming/index.js +++ b/streaming/index.js @@ -45,7 +45,7 @@ const authenticationMiddleware = (req, res, next) => { 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() if (err) { @@ -115,8 +115,13 @@ const streamFrom = (id, req, res, needsFiltering = false) => { } }) - // Heartbeat to keep connection alive - setInterval(() => res.write(':thump\n'), 15000) + const heartbeat = 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) } |