mirror of
https://github.com/fluencelabs/js-libp2p-tcp
synced 2025-04-25 11:42:31 +00:00
fix: clearing timeout when closes (#87)
This commit is contained in:
parent
d804244239
commit
f8f52665f7
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user