Skip to content

Commit

Permalink
Unlink socket before using
Browse files Browse the repository at this point in the history
  • Loading branch information
nhooyr committed Oct 9, 2020
1 parent daa1c86 commit e520087
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/node/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,18 @@ export class HttpServer {
*/
public listen(): Promise<string | null> {
if (!this.listenPromise) {
this.listenPromise = new Promise((resolve, reject) => {
this.listenPromise = new Promise(async (resolve, reject) => {
this.server.on("error", reject)
this.server.on("upgrade", this.onUpgrade)
const onListen = (): void => resolve(this.address())
if (this.options.socket) {
try {
await fs.unlink(this.options.socket)
} catch (err) {
if (err.code !== "ENOENT") {
logger.warn(err.message)
}
}
this.server.listen(this.options.socket, onListen)
} else if (this.options.host) {
// [] is the correct format when using :: but Node errors with them.
Expand Down

0 comments on commit e520087

Please sign in to comment.