Skip to content

Commit 2d1de74

Browse files
authored
Unlink socket before using (#2181)
See https://stackoverflow.com/a/34881585/4283659 Closes #1538
1 parent c6c293d commit 2d1de74

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

.eslintrc.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ rules:
3030
eqeqeq: error
3131
import/order:
3232
[error, { alphabetize: { order: "asc" }, groups: [["builtin", "external", "internal"], "parent", "sibling"] }]
33+
no-async-promise-executor: off
3334

3435
settings:
3536
# Does not work with CommonJS unfortunately.

src/node/http.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -578,11 +578,18 @@ export class HttpServer {
578578
*/
579579
public listen(): Promise<string | null> {
580580
if (!this.listenPromise) {
581-
this.listenPromise = new Promise((resolve, reject) => {
581+
this.listenPromise = new Promise(async (resolve, reject) => {
582582
this.server.on("error", reject)
583583
this.server.on("upgrade", this.onUpgrade)
584584
const onListen = (): void => resolve(this.address())
585585
if (this.options.socket) {
586+
try {
587+
await fs.unlink(this.options.socket)
588+
} catch (err) {
589+
if (err.code !== "ENOENT") {
590+
logger.warn(err.message)
591+
}
592+
}
586593
this.server.listen(this.options.socket, onListen)
587594
} else if (this.options.host) {
588595
// [] is the correct format when using :: but Node errors with them.

0 commit comments

Comments
 (0)