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
|
callback = callback || noop
|
||||||
options = options || {}
|
options = options || {}
|
||||||
|
|
||||||
let closed = false
|
const timeout = setTimeout(() => {
|
||||||
server.close(callback)
|
|
||||||
|
|
||||||
server.once('close', () => {
|
|
||||||
closed = true
|
|
||||||
})
|
|
||||||
setTimeout(() => {
|
|
||||||
if (closed) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
log('unable to close graciously, destroying conns')
|
log('unable to close graciously, destroying conns')
|
||||||
Object.keys(server.__connections).forEach((key) => {
|
Object.keys(server.__connections).forEach((key) => {
|
||||||
log('destroying %s', key)
|
log('destroying %s', key)
|
||||||
server.__connections[key].destroy()
|
server.__connections[key].destroy()
|
||||||
})
|
})
|
||||||
}, options.timeout || CLOSE_TIMEOUT)
|
}, options.timeout || CLOSE_TIMEOUT)
|
||||||
|
|
||||||
|
server.close(callback)
|
||||||
|
|
||||||
|
server.once('close', () => {
|
||||||
|
clearTimeout(timeout)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let ipfsId
|
let ipfsId
|
||||||
|
Loading…
x
Reference in New Issue
Block a user