From a48ec1d5637398fd4e023bdbb6cc00399bf47631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 18 Aug 2023 13:48:18 +0200 Subject: fix(node/http): emit error when addr in use (#20200) Closes https://github.com/denoland/deno/issues/20186 --- ext/node/polyfills/http.ts | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'ext/node/polyfills') diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts index 609a046ac..52aac4cae 100644 --- a/ext/node/polyfills/http.ts +++ b/ext/node/polyfills/http.ts @@ -1610,19 +1610,25 @@ export class ServerImpl extends EventEmitter { return; } this.#ac = ac; - this.#server = serve( - { - handler: handler as Deno.ServeHandler, - ...this.#addr, - signal: ac.signal, - // @ts-ignore Might be any without `--unstable` flag - onListen: ({ port }) => { - this.#addr!.port = port; - this.emit("listening"); + try { + this.#server = serve( + { + handler: handler as Deno.ServeHandler, + ...this.#addr, + signal: ac.signal, + // @ts-ignore Might be any without `--unstable` flag + onListen: ({ port }) => { + this.#addr!.port = port; + this.emit("listening"); + }, + ...this._additionalServeOptions?.(), }, - ...this._additionalServeOptions?.(), - }, - ); + ); + } catch (e) { + this.emit("error", e); + return; + } + if (this.#unref) { this.#server.unref(); } -- cgit v1.2.3