From 2d1de749f46d3f961420d754d050d05339f3dc8f Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Fri, 9 Oct 2020 12:34:52 -0400 Subject: [PATCH] Unlink socket before using (#2181) See https://stackoverflow.com/a/34881585/4283659 Closes #1538 --- .eslintrc.yaml | 1 + src/node/http.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 306dd2c22..92657d629 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -30,6 +30,7 @@ rules: eqeqeq: error import/order: [error, { alphabetize: { order: "asc" }, groups: [["builtin", "external", "internal"], "parent", "sibling"] }] + no-async-promise-executor: off settings: # Does not work with CommonJS unfortunately. diff --git a/src/node/http.ts b/src/node/http.ts index 297dda0cc..c616c8837 100644 --- a/src/node/http.ts +++ b/src/node/http.ts @@ -578,11 +578,18 @@ export class HttpServer { */ public listen(): Promise { 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.