TooTallNate / proxy-agents

Node.js HTTP Proxy Agents Monorepo
https://proxy-agents.n8.io
919 stars 239 forks source link

Rotating Proxies #106

Closed yovanoc closed 1 year ago

yovanoc commented 4 years ago

Hello,

I tried to use rotating proxies with this agent.

I get a "Socket is closed". My opinion is that when the agent request the service to get another proxy the socket is closed here and not follow the real proxy

(node:85823) UnhandledPromiseRejectionWarning: RequestError: Socket is closed
    at ClientRequest.<anonymous> (/Users/devchris/Documents/code/nodejs/tmp/project/node_modules/got/dist/source/core/index.js:826:25)
    at Object.onceWrapper (events.js:422:26)
    at ClientRequest.emit (events.js:327:22)
    at ClientRequest.origin.emit (/Users/devchris/Documents/code/nodejs/tmp/project/node_modules/@szmarczak/http-timer/dist/source/index.js:39:20)
    at Socket.socketErrorListener (_http_client.js:467:9)
    at Socket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:100:8)
    at errorOrDestroy (internal/streams/destroy.js:158:7)
    at onwriteError (_stream_writable.js:391:3)
    at processTicksAndRejections (internal/process/task_queues.js:86:21)
    at Socket._writeGeneric (net.js:772:8)
    at Socket._write (net.js:794:8)
    at doWrite (_stream_writable.js:377:12)
    at clearBuffer (_stream_writable.js:517:7)
    at Socket.Writable.uncork (_stream_writable.js:317:7)
    at ClientRequest._flushOutput (_http_outgoing.js:883:10)
    at ClientRequest._flush (_http_outgoing.js:852:22)
    at _http_client.js:323:47
    at callSocketMethod (_http_client.js:818:7)
    at ClientRequest.onSocket (_http_client.js:823:7)

But when I use this lib https://github.com/koichik/node-tunnel all is working good. But i would like to use https-proxy-agent. Rotating proxy is really working or not?

TooTallNate commented 4 years ago

What do you mean by "rotating proxies"? Can you show some example code?

yovanoc commented 4 years ago

Like https://smartproxy.com/.

Its a simple proxy that redirect to a fresh proxy for each request, but here, I think when he switch from the first to the second the socket is closed instead of following to the real proxy

yovanoc commented 4 years ago

News for this, only happened with node 14, on node 12 all is fine! I didn't dig deeper this but only changing node version "fix" this issue

leonardomso commented 4 years ago

Hi @yovanoc, can you provide an example of how you got it working? I am currently trying to work with rotating proxies in Node.js and I am getting some errors related to socket.

yovanoc commented 4 years ago

@leonardomso I use Got with http2 option and this to proxy https://github.com/szmarczak/http2-wrapper

leonardomso commented 4 years ago

@yovanoc can you show me an example, please?

yovanoc commented 4 years ago
import got from "got";
import http2 from "http2-wrapper";

const agent = new http2.proxies.Http2OverHttp({
  url: "http://username:password@ip:port", // YOUR PROXY HERE
  proxyOptions: {
    // If the proxy doesn't process TLS sockets automatically, set this to `true`.
    raw: true
 }
});

const client = got.extend({
    http2: true,
    agent: {
      http2: agent
    },
});
LuizFelipeNeves commented 3 years ago

@yovanoc thanks!

TooTallNate commented 1 year ago

This module has gone through a large refactor and modernization. I am closing this issue as a bit of house cleaning. If you feel that this issue still exists in the latest release, feel free to open a new issue.