summaryrefslogtreecommitdiff
path: root/cli/tests/unit/http_test.ts
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2022-10-24 00:45:45 +0200
committerGitHub <noreply@github.com>2022-10-24 00:45:45 +0200
commit38213f1142200e9184d1c5ae1e25ff781248362a (patch)
treedf73b82893501016251d4e0f845a2dfab6b500f4 /cli/tests/unit/http_test.ts
parent0e1167d12d116be7ba1855252b5ca4d668bf3472 (diff)
fix(ext/net): don't remove sockets on unix listen (#16394)
When listening on a UNIX socket path, Deno currently tries to unlink this path prior to actually listening. The implementation of this behaviour is VERY racy, involves 2 additional syscalls, and does not match the behaviour of any other runtime (Node.js, Go, Rust, etc). This commit removes this behaviour. If a user wants to listen on an existing socket, they must now unlink the file themselves prior to listening. This change in behaviour only impacts --unstable APIs, so it is not a breaking change.
Diffstat (limited to 'cli/tests/unit/http_test.ts')
-rw-r--r--cli/tests/unit/http_test.ts12
1 files changed, 9 insertions, 3 deletions
diff --git a/cli/tests/unit/http_test.ts b/cli/tests/unit/http_test.ts
index 566efce6d..e2a7c2451 100644
--- a/cli/tests/unit/http_test.ts
+++ b/cli/tests/unit/http_test.ts
@@ -16,6 +16,7 @@ import {
delay,
fail,
} from "./test_util.ts";
+import { join } from "../../../test_util/std/path/mod.ts";
async function writeRequestAndReadResponse(conn: Deno.Conn): Promise<string> {
const encoder = new TextEncoder();
@@ -1290,6 +1291,11 @@ Deno.test(
},
);
+function tmpUnixSocketPath(): string {
+ const folder = Deno.makeTempDirSync();
+ return join(folder, "socket");
+}
+
// https://github.com/denoland/deno/pull/13628
Deno.test(
{
@@ -1297,7 +1303,7 @@ Deno.test(
permissions: { read: true, write: true },
},
async function httpServerOnUnixSocket() {
- const filePath = Deno.makeTempFileSync();
+ const filePath = tmpUnixSocketPath();
let httpConn: Deno.HttpConn;
const promise = (async () => {
@@ -2239,7 +2245,7 @@ Deno.test("upgradeHttp unix", {
permissions: { read: true, write: true },
ignore: Deno.build.os === "windows",
}, async () => {
- const filePath = Deno.makeTempFileSync();
+ const filePath = tmpUnixSocketPath();
const promise = deferred();
async function client() {
@@ -2435,7 +2441,7 @@ Deno.test(
permissions: { read: true, write: true },
},
async function httpServerWithoutExclusiveAccessToUnixSocket() {
- const filePath = await Deno.makeTempFile();
+ const filePath = tmpUnixSocketPath();
const listener = Deno.listen({ path: filePath, transport: "unix" });
const [clientConn, serverConn] = await Promise.all([