未验证 提交 2d1de749 编写于 作者: A Anmol Sethi 提交者: GitHub

Unlink socket before using (#2181)

See https://stackoverflow.com/a/34881585/4283659

Closes #1538
上级 c6c293d5
......@@ -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.
......
......@@ -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.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册