Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
fix: clearing timeout when closes (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgte authored and daviddias committed Feb 7, 2018
1 parent d804244 commit f8f5266
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,19 @@ module.exports = (handler) => {
callback = callback || noop
options = options || {}

let closed = false
server.close(callback)

server.once('close', () => {
closed = true
})
setTimeout(() => {
if (closed) {
return
}

const timeout = setTimeout(() => {
log('unable to close graciously, destroying conns')
Object.keys(server.__connections).forEach((key) => {
log('destroying %s', key)
server.__connections[key].destroy()
})
}, options.timeout || CLOSE_TIMEOUT)

server.close(callback)

server.once('close', () => {
clearTimeout(timeout)
})
}

let ipfsId
Expand Down

0 comments on commit f8f5266

Please sign in to comment.