Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deno 2.1.4 - node:http's http.request socketPath option fails in Deno, but works in Node. #27675

Open
tenkoverse opened this issue Jan 15, 2025 · 0 comments

Comments

@tenkoverse
Copy link

Summary:

  • Deno's node:http module behaves differently than Node.js's http module when using http.request with the socketPath option to connect to the Docker socket.
  • Instead of connecting to the Docker socket, Deno appears to attempt a TCP connection to http://localhost/info, resulting in an ECONNREFUSED error.
  • This discrepancy was discovered while troubleshooting a failure using @testcontainers/postgresql library and was traced down through its dependencies (dockerode, docker-modem) to this minimal reproduction.
  • The equivalent code works perfectly in node, indicating a failure in Deno.

Reproduction Steps:

1. Setup:

  • Install Docker Desktop on macOS.
  • Ensure the Docker daemon is running and accessible via the default Unix socket: /Users/<your_username>/.docker/run/docker.sock (replace <your_username> with your actual username).
  • Make sure you have "Allow the default Docker socket to be used" enabled under advanced settings in Docker.

2. Node.js (Correct Behavior):

Create a file named node-test.js with the following content:
Ensure you set "type": "module" in package.json.

import http from "http";

const options = {
  socketPath: "/Users/<your_username>/.docker/run/docker.sock", 
  path: "/info",
  method: "GET",
};

const req = http.request(options, () => {
  console.log(`Success`);
});

req.on("error", (e) => {
  console.error(`Error: ${e.message}`);
});

req.end();

Run: node node-test.js

  • Expected Output:
Success
  • Actual Output:
Success

3. Deno (Incorrect Behavior):

  • Create a file named deno-test.ts with the following content:
import http from "node:http";

const options = {
  socketPath: "/Users/<your_username>/.docker/run/docker.sock", 
  path: "/info",
  method: "GET",
};

const req = http.request(options, () => {
  console.log(`Success`);
});

req.on("error", (e) => {
  console.error(`Error: ${e.message}`);
});

req.end();

Run deno -A deno-test.ts

  • Expected Output:
Success
  • Actual Output:
Error: error sending request for url (http://localhost/info): client error (Connect): tcp connect error: Connection refused (os error 61): Connection refused (os error 61)

Environment:

deno 2.1.4 (stable, release, x86_64-apple-darwin)
v8 13.0.245.12-rusty
typescript 5.6.2

Docker Desktop: 4.37.2 (179585)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant