apify / proxy-chain

Node.js implementation of a proxy server (think Squid) with support for SSL, authentication and upstream proxy chaining.

Home Page:https://www.npmjs.com/package/proxy-chain

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Client network socket disconnected before secure TLS connection was established

scottk opened this issue · comments

Hi,

I ran into an error where sometimes when running a server, it fails to secure a socket connection. Here's the stack trace:

{ Error: Client network socket disconnected before secure TLS connection was established
at TLSSocket.onConnectEnd (_tls_wrap.js:1088:19)
at Object.onceWrapper (events.js:277:13)
at TLSSocket.emit (events.js:194:15)
at endReadableNT (_stream_readable.js:1103:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
code: 'ECONNRESET',
path: undefined,
host: null,
port: null,
localAddress: undefined }

Killing and starting the server over again fixes it (does not re-occur), but it happens in about 1 in 3 runs, and happens for every request. This is the trace on the server side:

Server[80]: 3 | Using HandlerTunnelChain
Server[80]: 3 | Connecting to upstream proxy...
Server[80]: 3 | Target socket assigned
Server[80]: 3 | Connected to upstream proxy
Server[80]: 3 | Target socket ended
Server[80]: 3 | Target socket closed
Server[80]: 3 | Source socket ended
Server[80]: 3 | Closing handler
Connection 3 closed
{ srcTxBytes: 203,
srcRxBytes: 139,
trgTxBytes: 143,
trgRxBytes: 205 }

Here's the request I'm making (which goes to an upstream proxy provider):

`
const userAgent = new UserAgent();
const userAgentString = userAgent.toString();
var agent = new HttpsProxyAgent(proxy_url);

request(
{
url: "https://example.com",
agent: agent,
method: 'get',
gzip: true,
headers: {
'User-Agent': userAgentString,
}
},
function(err, res, body) {
console.log(err)
}
)
`

What upstream proxy are you using, perhaps it disconnects too early? It would be great if you could provide the full code to reproduce this problem.

Thanks for the response, I'm using Smartproxy as the upstream provider. I haven't been able to pinpoint the exact conditions to replicate it, but there are two scenarios from startup of proxy-chain - it either works completely or this error occurs on every request. I'll continue running and monitoring to provide a better idea of what's going on - but right now it seems like if a socket disconnects upstream in an abnormal way, all subsequent connections do so.

This could also be explained by the upstream proxy being in some broken state. It's really hard to say without a working reproduction. BTW we're using the proxy-chain package on production to handle millions of HTTPS connection, and don't experience this issue...