diff options
author | Leo Kettmeir <crowlkats@toaxl.com> | 2023-07-19 00:33:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-19 00:33:43 +0200 |
commit | bab0294db674c64c18243a877e9dff5f9a91c923 (patch) | |
tree | 117697ad9203478e63d782f1c22c51c08f251764 | |
parent | 51b3534b3d3833667e8c029564bebf319b0d2596 (diff) |
fix(node/net): Server connection callback include socket value (#19779)
-rw-r--r-- | cli/tests/unit_node/net_test.ts | 38 | ||||
-rw-r--r-- | ext/node/polyfills/net.ts | 2 |
2 files changed, 38 insertions, 2 deletions
diff --git a/cli/tests/unit_node/net_test.ts b/cli/tests/unit_node/net_test.ts index 442f7e61e..3b78cbe32 100644 --- a/cli/tests/unit_node/net_test.ts +++ b/cli/tests/unit_node/net_test.ts @@ -1,11 +1,13 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import * as net from "node:net"; -import { assertEquals } from "../../../test_util/std/testing/asserts.ts"; +import { + assert, + assertEquals, +} from "../../../test_util/std/testing/asserts.ts"; import { deferred } from "../../../test_util/std/async/deferred.ts"; import * as path from "../../../test_util/std/path/mod.ts"; import * as http from "node:http"; -import { assert } from "../../../test_util/std/testing/asserts.ts"; Deno.test("[node/net] close event emits after error event", async () => { const socket = net.createConnection(27009, "doesnotexist"); @@ -96,3 +98,35 @@ Deno.test({ } }, }); + +Deno.test("[node/net] connection event has socket value", async () => { + const p = deferred(); + const p2 = deferred(); + + const server = net.createServer(); + server.on("error", p.reject); + server.on("connection", (socket) => { + assert(socket !== undefined); + socket.end(); + server.close(() => { + p.resolve(); + }); + }); + server.listen(async () => { + // deno-lint-ignore no-explicit-any + const { port } = server.address() as any; + + const conn = await Deno.connect({ + port, + transport: "tcp", + }); + + for await (const _ of conn.readable) { + // + } + + p2.resolve(); + }); + + await Promise.all([p, p2]); +}); diff --git a/ext/node/polyfills/net.ts b/ext/node/polyfills/net.ts index fb1c1bdb6..bcc982d3b 100644 --- a/ext/node/polyfills/net.ts +++ b/ext/node/polyfills/net.ts @@ -2374,6 +2374,8 @@ export class Server extends EventEmitter { socket._server = this; DTRACE_NET_SERVER_CONNECTION(socket); + + return socket; } _listen2 = _setupListenHandle; |