summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-08-18 13:48:18 +0200
committerGitHub <noreply@github.com>2023-08-18 13:48:18 +0200
commita48ec1d5637398fd4e023bdbb6cc00399bf47631 (patch)
tree1de36ae053a60faaafc1310b78e8510631965dca /ext
parentc77c836a238ce683b21c12f88cd1101b930ce042 (diff)
fix(node/http): emit error when addr in use (#20200)
Closes https://github.com/denoland/deno/issues/20186
Diffstat (limited to 'ext')
-rw-r--r--ext/node/polyfills/http.ts30
1 files changed, 18 insertions, 12 deletions
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();
}