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

BadResource error when using socks proxy with ws client #27974

Open
MrYellowSock opened this issue Feb 5, 2025 · 0 comments
Open

BadResource error when using socks proxy with ws client #27974

MrYellowSock opened this issue Feb 5, 2025 · 0 comments

Comments

@MrYellowSock
Copy link

Version: Deno 2.1.9
Code

import WebSocket from "ws";

import { SocksProxyAgent } from "socks-proxy-agent";

const proxyUrl = "socks5://127.0.0.1:9999";

const agent = new SocksProxyAgent(proxyUrl);

const wsUrl = "wss://echo.websocket.org";

const ws = new WebSocket(wsUrl, { agent });

ws.on("open", () => {
  ws.send("Hello Server!");
});

ws.on("message", (data) => {
  console.log("Received:", data.toString());
});

ws.on("error", (err) => {
  console.error("WebSocket error:", err);
});

ws.on("close", () => {
  console.log("Connection closed");
});

deno.json

{
	"tasks": {},
	"imports": {
		"@std/assert": "jsr:@std/assert@1",
		"https-proxy-agent": "npm:https-proxy-agent@^7.0.6",
		"socks-proxy-agent": "npm:socks-proxy-agent@^8.0.5",
		"ws": "npm:ws@^8.18.0"
	}
}

Output

WebSocket error: BadResource: Bad resource ID
    at node:http:317:27
    at HttpsClientRequest._writeHeader (node:http:440:7)
    at HttpsClientRequest._flushHeaders (node:_http_outgoing:382:12)
    at onConnect (node:http:486:16)
    at node:http:499:11
    at processTicksAndRejections (ext:deno_node/_next_tick.ts:28:11)
    at runNextTicks (ext:deno_node/_next_tick.ts:76:3)
    at eventLoopTick (ext:core/01_core.js:184:21) {
  name: "BadResource"
}
Connection closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants