Skip to content

Commit

Permalink
fix(HttpServer): make killable (destroy all open sockets)
Browse files Browse the repository at this point in the history
  • Loading branch information
nokome committed Nov 29, 2018
1 parent 17adfc2 commit 5dfdcf6
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/comms/HttpServer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import express from 'express'
import getPort from 'get-port'
import http from 'http'
// @ts-ignore
import killable from 'killable'

import Server from './Server'
import Processor from '../Processor'
Expand Down Expand Up @@ -86,18 +88,23 @@ export default class HttpServer extends Server {
async start () {
this.port = await getPort({ port: this.port }) // tslint:disable-line:await-promise
return new Promise((resolve, reject) => {
this.server = this.app.listen(this.port, this.address, () => {
this.server = killable(this.app.listen(this.port, this.address, () => {
this.log({ started: `http://${this.address}:${this.port}` })
resolve()
})
}))
})
}

async stop () {
if (this.server) {
this.server.close()
this.server = undefined
this.log({ stopped: true })
return new Promise((resolve, reject) => {
// @ts-ignore
this.server.kill(() => {
this.server = undefined
this.log({ stopped: true })
resolve()
})
})
}
}
}

0 comments on commit 5dfdcf6

Please sign in to comment.