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

Commit f8f5266

Browse files
pgtedaviddias
authored andcommitted
fix: clearing timeout when closes (#87)
1 parent d804244 commit f8f5266

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/listener.js

+7-11
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,19 @@ module.exports = (handler) => {
5555
callback = callback || noop
5656
options = options || {}
5757

58-
let closed = false
59-
server.close(callback)
60-
61-
server.once('close', () => {
62-
closed = true
63-
})
64-
setTimeout(() => {
65-
if (closed) {
66-
return
67-
}
68-
58+
const timeout = setTimeout(() => {
6959
log('unable to close graciously, destroying conns')
7060
Object.keys(server.__connections).forEach((key) => {
7161
log('destroying %s', key)
7262
server.__connections[key].destroy()
7363
})
7464
}, options.timeout || CLOSE_TIMEOUT)
65+
66+
server.close(callback)
67+
68+
server.once('close', () => {
69+
clearTimeout(timeout)
70+
})
7571
}
7672

7773
let ipfsId

0 commit comments

Comments
 (0)