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

Not caught Error: Client network socket disconnected before secure TLS connection was established #277

Open
AidanWelch opened this issue Feb 6, 2024 · 4 comments

Comments

@AidanWelch
Copy link

It's normal that some proxied requests fail, so I have simple error handling, the issue is that the error is not being caught and instead crashing the script,

import { HttpsProxyAgent } from 'https-proxy-agent';
import fetch from 'node-fetch';

const agent = new HttpsProxyAgent( process.env.PROXY_STRING );

let err;
const casePageResponse = await fetch( `foo.bar`, { agent })
	.catch( e => err = e );

Crashes with this error:

node:events:497
      throw er; // Unhandled 'error' event
      ^

Error: Client network socket disconnected before secure TLS connection was established
    at TLSSocket.onConnectEnd (node:_tls_wrap:1727:19)
    at TLSSocket.emit (node:events:531:35)
    at endReadableNT (node:internal/streams/readable:1696:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on TLSSocket instance at:
    at emitErrorNT (node:internal/streams/destroy:169:8)
    at emitErrorCloseNT (node:internal/streams/destroy:128:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  code: 'ECONNRESET',
  path: undefined,
  host: 'us-pr.oxylabs.io',
  port: 10000,
  localAddress: undefined
}

It doesn't get caught in the catch statement.

@AidanWelch
Copy link
Author

Probably an error with node-fetch as seen on this tangentially related issue: node-fetch/node-fetch#892

@AidanWelch
Copy link
Author

Actually I get it with node:https too, also not being caught by req.on('error', console.error)

@AidanWelch
Copy link
Author

passing rejectUnauthorized like so:

const agent = new HttpsProxyAgent( process.env.PROXY_STRING, { rejectUnauthorized: false });

stops this error specifically, but the issue is still that it doesn't throw the error.

@florrdv
Copy link

florrdv commented Apr 17, 2024

Having the same issue here!

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

2 participants