TooTallNate / proxy-agents

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

complete crash without warning on 'Proxy CONNECT aborted' #102

Closed ghost closed 1 year ago

ghost commented 4 years ago

I have this error that I don't know how to reproduce because I don't own the proxy server that produces it. But it is rather critical because it crashes any application without possible way to catch it.

The code below causes the crash without warning. The console logs never trigger. No errors is outputted. Application immediately exits. I have tried with node-fetch and make-fetch-happen as well and still the same issue. http-proxy-agent has no issue.

import fetch from 'isomorphic-fetch'
import HttpsProxyAgent from 'https-proxy-agent'

const fetchWithProxy = async (url, {proxy, proxyUsername, proxyPassword}) => {
  let proxyUri
  if (proxyUsername) {
    proxyUri = `http://${proxyUsername}:${proxyPassword}@${proxy}`
  }
  else {
    proxyUri = `http://${proxy}`
  }

  let agent = new HttpsProxyAgent(proxyUri)

  const res = await fetch(encodeURI(url), {agent}).then(res => res.text())
  console.log({res})
  return res
}

;(async () => {
  const proxy = require('secret/proxyProviders')['proxy1']
  const res = await fetchWithProxy('https://bot.whatismyipaddress.com', proxy)
  console.log('done')
})()

If I curl the proxy server I get

curl -v --proxy http://user:pass@111.111.111.111:3000 https://example.com

* Rebuilt URL to: https://example.com/
*   Trying 111.111.111.111...
* TCP_NODELAY set
* Connected to 111.111.111.111 (111.111.111.111) port 3000 (#0)
* Establish HTTP proxy tunnel to example.com:443
* Proxy auth using Basic with user '...'
> CONNECT example.com:443 HTTP/1.1
> Host: example.com:443
> Proxy-Authorization: Basic ...
> User-Agent: curl/7.54.0
> Proxy-Connection: Keep-Alive
> 
* Proxy CONNECT aborted
* Connection #0 to host 111.111.111.111 left intact
curl: (56) Proxy CONNECT aborted

if I curl to an http site I get:

curl -v --proxy http://user:pass@111.111.111.111:3000 http://example.com

* Rebuilt URL to: http://example.com/
*   Trying 111.111.111.111...
* TCP_NODELAY set
* Connected to 111.111.111.111 (111.111.111.111) port 3000 (#0)
* Proxy auth using Basic with user '...'
> GET http://example.com/ HTTP/1.1
> Host: example.com
> Proxy-Authorization: Basic ...
> User-Agent: curl/7.54.0
> Accept: */*
> Proxy-Connection: Keep-Alive
> 
< HTTP/1.1 502 Bad Gateway
< Server: squid/3.3.8
< Mime-Version: 1.0
< Date: Sat, 09 May 2020 19:10:29 GMT
< Content-Type: text/html
< Content-Length: 3297
< X-Squid-Error: ERR_READ_ERROR 104
< Vary: Accept-Language
< Content-Language: en
< X-Cache: MISS from 69550946e4e6
< X-Cache-Lookup: MISS from 69550946e4e6:3128
< Connection: keep-alive
< 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ERROR: The requested URL could not be retrieved</title>
<style type="text/css"><!-- 
 /*
 Stylesheet for Squid Error pages
 Adapted from design by Free CSS Templates
 http://www.freecsstemplates.org
 Released for free under a Creative Commons Attribution 2.5 License
*/

</head><body id=ERR_READ_ERROR>
<div id="titles">
<h1>ERROR</h1>
<h2>The requested URL could not be retrieved</h2>
</div>
<hr>

<div id="content">
<p>The following error was encountered while trying to retrieve the URL: <a href="http://example.com/">http://example.com/</a></p>

<blockquote id="error">
<p><b>Read Error</b></p>
</blockquote>

<p id="sysmsg">The system returned: <i>(104) Connection reset by peer</i></p>

<p>An error condition occurred while reading data from the network. Please retry your request.</p>

<p>Your cache administrator is ...</p>
<br>
</div>

<hr>
<div id="footer">
<p>Generated Sat, 09 May 2020 19:10:29 GMT by 69550946e4e6 (squid/3.3.8)</p>
<!-- ERR_READ_ERROR -->
</div>
</body></html>
* Connection #0 to host 111.111.111.111 left intact

I know I'm not the only one getting this bug https://github.com/node-fetch/node-fetch/issues/739

It's probably not possible to fix it just based on this information since I dont know how to reproduce it, but maybe someone can figure it out eventually.

ozican commented 4 years ago

same for me

pmioduszewski commented 3 years ago

same here 😞

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.