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

Fetch returns: Error trying to connect: Connection reset by peer (os error 54) #6197

Open
jeffreyvdhondel opened this issue Jun 9, 2020 · 21 comments
Labels
bug Something isn't working correctly web related to Web APIs

Comments

@jeffreyvdhondel
Copy link

jeffreyvdhondel commented Jun 9, 2020

let a = await fetch('https://pictures.vwe.nl'); console.log(a)

Returns "Error trying to connect: Connection reset by peer (os error 54)"

deno --version

  • deno 1.0.5
  • v8 8.4.300
  • typescript 3.9.2
@gaurav219
Copy link

The URL https://pictures.vwe.nl results in a 403 (Forbidden Acess), if you open in a browser.

Correct me, if I misinterpreted your issue.

@jeffreyvdhondel
Copy link
Author

Yes thats correct i would like to do a.statuscode to know the http status code of the request.

@bartlomieju bartlomieju added bug Something isn't working correctly web related to Web APIs labels Jun 16, 2020
@iugo
Copy link
Contributor

iugo commented Sep 7, 2020

ConnectionReset: Connection reset by peer (os error 104)

error: Uncaught ConnectionReset: Connection reset by peer (os error 104)
  at unwrapResponse (rt/10_dispatch_json.js:24:13)
  at sendAsync (rt/10_dispatch_json.js:75:12)
  at async TLSListener.accept (rt/40_tls.js:42:19)
  at async Server.acceptConnAndIterateHttpRequests
  at async MuxAsyncIterator.callIteratorNext

@erfanium
Copy link
Contributor

erfanium commented Sep 16, 2020

@bartlomieju
This problem is from rustls, This can be closed. (May add better error handler for this)

@lucacasonato
Copy link
Member

This error looks to be solved in 1.4:

fetch('https://pictures.vwe.nl').then(console.log)
Promise { <pending> }
Response {
  _bodySource: ReadableStream { locked: false },
  _stream: null,
  url: "https://pictures.vwe.nl",
  statusText: "Forbidden",
  status: 403,
  headers: Headers { content-type: text/html, server: Microsoft-IIS/10.0, x-powered-by: ASP.NET, date: Thu, 17 Sep 2020 09:58:52 GMT, content-length: 1233 },
  redirected: false,
  type: "default"
}

@wperron
Copy link
Contributor

wperron commented Jun 9, 2021

Reopening because we're getting reports of a regression in Discord since at least 1.9, possibly earlier https://discord.com/channels/684898665143206084/689420767620104201/852181010614976533

@wperron wperron reopened this Jun 9, 2021
@searchableguy
Copy link

This error looks to be solved in 1.4:

fetch('https://pictures.vwe.nl').then(console.log)
Promise { <pending> }
Response {
  _bodySource: ReadableStream { locked: false },
  _stream: null,
  url: "https://pictures.vwe.nl",
  statusText: "Forbidden",
  status: 403,
  headers: Headers { content-type: text/html, server: Microsoft-IIS/10.0, x-powered-by: ASP.NET, date: Thu, 17 Sep 2020 09:58:52 GMT, content-length: 1233 },
  redirected: false,
  type: "default"
}

I tried running the same on deno 1.4.0 and I am getting the same error.

deno 1.4.0
v8 8.7.75
typescript 4.0.2
deno run -A --log-level=debug test.ts
Deno isolate init with snapshots.
rust:shared_queue:reset
DEBUG JS - cwd /home/user/Projects/deno/import_js
DEBUG JS - args []
main_module file:///home/user/Projects/deno/import_js/test.ts
fetch_source_file specifier: file:///home/user/Projects/deno/import_js/test.ts maybe_referrer: None
⚠️️  Granted read access to "/home/user/Projects/deno/import_js/test.ts"
compiled filename: "/home/user/.cache/deno/gen/file/home/user/Projects/deno/import_js/test.ts.js"
register_complete file:///home/user/Projects/deno/import_js/test.ts
DEBUG JS - sendAsync op_fetch
⚠️️  Granted network access to "https://api.sl.se/"
Before fetch https://api.sl.se
starting new connection: https://api.sl.se/
resolving host="api.sl.se" 
connecting to 194.68.78.66:443 
connected to 194.68.78.66:443 
No cached session for DNSNameRef("api.sl.se")
Not resuming any session
rust:shared_queue:pre-push: op=8, off=812, end=983, len=171, aligned_end=984
rust:shared_queue:push: num_records=1, num_shifted_off=0, head=984
DEBUG JS - sendSync op_apply_source_map
DEBUG JS - sendSync op_apply_source_map
DEBUG JS - sendSync op_apply_source_map
error: Uncaught Http: error sending request for url (https://api.sl.se/): error trying to connect: Connection reset by peer (os error 104)
    at unwrapResponse (deno:cli/rt/10_dispatch_json.js:24:13)
    at sendAsync (deno:cli/rt/10_dispatch_json.js:75:12)
    at async fetch (deno:cli/rt/26_fetch.js:279:29)

@jsejcksn
Copy link
Contributor

I encountered this today as well:

% deno
Deno 1.11.1
exit using ctrl+d or close()
> await fetch("https://www.co.walton.fl.us/523/Morrison-Springs");
Uncaught TypeError: error sending request for url (https://www.co.walton.fl.us/523/Morrison-Springs): error trying to connect: Connection reset by peer (os error 54)
    at deno:core/core.js:86:46
    at unwrapOpResult (deno:core/core.js:106:13)
    at async mainFetch (deno:extensions/fetch/26_fetch.js:228:14)

and here's the beginning of the verbose curl output (I'm truncating it before the headers):

% curl -s -v -D - -o /dev/null "https://www.co.walton.fl.us/523/Morrison-Springs"
*   Trying 208.90.188.209...
* TCP_NODELAY set
* Connected to www.co.walton.fl.us (208.90.188.209) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/cert.pem
  CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
} [233 bytes data]
* TLSv1.2 (IN), TLS handshake, Server hello (2):
{ [85 bytes data]
* TLSv1.2 (IN), TLS handshake, Certificate (11):
{ [3053 bytes data]
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
{ [333 bytes data]
* TLSv1.2 (IN), TLS handshake, Server finished (14):
{ [4 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
} [70 bytes data]
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
} [1 bytes data]
* TLSv1.2 (OUT), TLS handshake, Finished (20):
} [16 bytes data]
* TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
{ [1 bytes data]
* TLSv1.2 (IN), TLS handshake, Finished (20):
{ [16 bytes data]
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: CN=www.co.walton.fl.us
*  start date: Sep 23 00:00:00 2020 GMT
*  expire date: Sep 23 23:59:59 2021 GMT
*  subjectAltName: host "www.co.walton.fl.us" matched cert's "www.co.walton.fl.us"
*  issuer: C=GB; ST=Greater Manchester; L=Salford; O=Sectigo Limited; CN=Sectigo RSA Domain Validation Secure Server CA
*  SSL certificate verify ok.
> GET /523/Morrison-Springs HTTP/1.1
> Host: www.co.walton.fl.us
> User-Agent: curl/7.64.1
> Accept: */*
> 
< HTTP/1.1 200 OK

This seemed odd to me:

ALPN, server did not agree to a protocol

but I'm guessing it just means the server didn't accept http/2?

@erfanium
Copy link
Contributor

erfanium commented Jun 21, 2021

As I said before, This problem is not about Deno itself.

Reproduce steps with reqwest + rustls:

Cargo.toml:

[dependencies]
reqwest = { version = "0.11", default-features = false, features = ["rustls-tls", "json"] }
tokio = { version = "1", features = ["full"] }

main.rs

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let resp = reqwest::get("https://www.co.walton.fl.us/523/Morrison-Springs")
        .await?
        .text()
        .await?;
    println!("{:#?}", resp);
    Ok(())
}

output:

Error: reqwest::Error { kind: Request, url: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("www.co.walton.fl.us")), port: None, path: "/523/Morrison-Springs", query: None, fragment: None }, source: hyper::Error(Connect, Custom { kind: Other, error: Os { code: 104, kind: ConnectionReset, message: "Connection reset by peer" } }) }

There's no problem if you use native-tls instead of rustls

@wiremoons
Copy link

Hi

I had a long running (ie several hours) simple Deno program that just loops a fetch request every few minutes to look for any new articles at Hacker News. This ran for several hours with out issue, and then stopped with the error below.

Not sure if it is relevant or related to the similar errors being reported on this issues - so just in case it is of help.

Simon

error: Uncaught (in promise) TypeError: error sending request for url (https://hacker-news.firebaseio.com/v0/item/28318840.json): connection error: Connection reset by peer (os error 54)
    at deno:core/01_core.js:106:46
    at unwrapOpResult (deno:core/01_core.js:126:13)
    at async mainFetch (deno:ext/fetch/26_fetch.js:265:14)

Extract of some of the code that cased the above error:

const baseURL = "https://hacker-news.firebaseio.com/v0";

async function getItemByID(id: number): Promise<Item | undefined> {
  const endpoint = `${baseURL}/item/${id}.json`;
  const res = await fetch(endpoint);
  const item = await res.json();
  return item ?? undefined;
}

while (true) {
    const item = await getItemByID(id);

    // If item does not exists - pause
    if (!item) {
      await delay(60 * 1000);
      continue;
    }

// NB rest of code not shown as probably not relevant

Deno Version:

deno 1.13.2 (release, aarch64-apple-darwin)
v8 9.3.345.11
typescript 4.3.5

OS: Apple macOS 'Big Sur' version 11.5.2

@rockvcp
Copy link

rockvcp commented Mar 21, 2022

has anyone had a proper solution on this?
actually trying this from postman code snippet: js - fetch
TypeError: error sending request for url (https://3rd-party.api/Login): error trying to connect: Connection reset by peer (os error 54) at async mainFetch (deno:ext/fetch/26_fetch.js:259:14)

actually trying this from postman code snippet: js - fetch but still getting the error above.

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
  "AccountId": 1234,
  "BranchId": 1234,
  "UserName": "test",
  "Password": "test"
});

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("https://3rd-party.api/Login", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

appreciate if anyone can help thank you
OS: MacOS Monterey
Version: 12.2.1

@in64
Copy link

in64 commented Apr 5, 2022

I have the same problem

error: Uncaught (in promise) TypeError: error sending request for url (https://dynamodb.ap-east-1.amazonaws.com/): connection error: Connection reset by peer (os error 104)
    at async mainFetch (deno:ext/fetch/26_fetch.js:280:14)
    at async fetch (deno:ext/fetch/26_fetch.js:490:9)

Deno Version:

#deno -V
deno 1.20.4

centos8

@aapoalas
Copy link
Collaborator

Verified:

deno
Deno 1.30.3
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> await fetch("https://www.co.walton.fl.us/523/Morrison-Springs");
Uncaught TypeError: error sending request for url (https://www.co.walton.fl.us/523/Morrison-Springs): error trying to connect: Connection reset by peer (os error 104)
    at async mainFetch (internal:ext/fetch/26_fetch.js:267:14)
    at async fetch (internal:ext/fetch/26_fetch.js:491:9)
    at async <anonymous>:2:1

@mwk24
Copy link

mwk24 commented Jul 30, 2023

I'm having the same issue with firebase. (exact same code works fine with node) Code snippet:

const db = getFirestore(app);
  console.log(db);
  const ref = db.collection('xyzzy').limit(10);

  ref.onSnapshot((snapshot) => {
    snapshot.docs.forEach((doc) => {
      console.log(doc.data()['name']);
    });
  },
  (error) => {
    console.log(error);
  });

Throws as follows:

error: Uncaught TypeError: error sending request for url (http://firestore.googleapis.com:443/google.firestore.v1.Firestore/Listen): connection error: Connection reset by peer (os error 54)
   at async mainFetch (ext:deno_fetch/26_fetch.js:266:12)
   at async fetch (ext:deno_fetch/26_fetch.js:490:7)
   at async node:http2:144:28

As I mentioned, exact same code works fine with node.

@louis77
Copy link

louis77 commented Oct 27, 2023

The issue is still unsolved in:

deno 1.37.2 (release, aarch64-apple-darwin)
v8 11.8.172.13
typescript 5.2.2

Most external https URLs I try to fetch result in the following error:

Uncaught TypeError: error sending request for url (https://[redacted]): error trying to connect: Connection reset by peer (os error 54)
    at async mainFetch (ext:deno_fetch/26_fetch.js:277:12)
    at async fetch (ext:deno_fetch/26_fetch.js:504:7)
    at async <anonymous>:2:14

Curl says:

* Connected to [redacted] port 443 (#0)
* ALPN: offers h2,http/1.1
* (304) (OUT), TLS handshake, Client hello (1):
*  CAfile: /etc/ssl/cert.pem
*  CApath: none
* (304) (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-SHA384
* ALPN: server did not agree on a protocol. Uses default.
* Server certificate:
*  subject: CN=*.[redacted]
*  start date: Nov 15 07:21:50 2022 GMT
*  expire date: Dec 17 07:21:49 2023 GMT
*  subjectAltName: host "[redacted]" matched cert's "[redacted]"
*  issuer: C=BE; O=GlobalSign nv-sa; CN=AlphaSSL CA - SHA256 - G2
*  SSL certificate verify ok.

Almost always I try to start a project with Deno I end up with this, for the past two years, making it impossible to use Deno or Deno Deploy.

The same fetch works in Node, Bun, and literally every other runtime/language I tried.

@iuioiua
Copy link
Contributor

iuioiua commented Oct 27, 2023

@louis77, can you provide a snippet? I'm unsure of your use case, but are you aware of Deno.HttpClient?

@louis77
Copy link

louis77 commented Oct 27, 2023

@iuioiua I've tried with Deno.HttpClient, but it has the same problem. There is nothing wrong with the certificate of the remote, it seems to be a TLS issue that Deno struggles with.

It is just a single line of fetch:

    const resp = await fetch(myUrl, {
        headers: {
            'Authorization': `Basic ${btoa('[user:pass]')}`,
        },
    })

With that line, I immediately get the os error 54 exception as reported by the other commenters on this issue. Since I have no "custom certificate", Deno.httpClient did not make any change here.

Unfortunately I can't share the remote URL here, but if you are on Discord or somewhere I'd be glad to send you the full fetch line so you can test it on your side.

@pvaldesoiro
Copy link

I found this same error, and got stuck since I am not able to connect to the provider's API. Exactly same fetch work perfectly fine with Node:

deno 1.37.2 (release, aarch64-apple-darwin)
v8 11.8.172.13
typescript 5.2.2

error:

cause: TypeError: error sending request for url (https://[redacted]): error trying to connect: Connection reset by peer (os error 54)
    at async Promise.all (index 0)
    at async node:http:432:26

curl -v:

* Connected to [redacted] port 443 (#0)
* ALPN: offers h2,http/1.1
* (304) (OUT), TLS handshake, Client hello (1):
*  CAfile: /etc/ssl/cert.pem
*  CApath: none
* (304) (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-SHA384
* ALPN: server did not agree on a protocol. Uses default.
* Server certificate:
*  subject: [redacted]
*  start date: Sep 22 07:33:14 2023 GMT
*  expire date: Sep 21 07:33:13 2024 GMT
*  subjectAltName: host [redacted] matched cert's [redacted]
*  issuer: [redacted]
*  SSL certificate verify ok.

@Kieran-who
Copy link

Came across the same issue yesterday. App has been operating fine then yesterday with no apparent changes, started seeing the same error for calls to external APIs and APIs from apps running in docker on the same machine.

@birgersp
Copy link

I am getting this in an import statement:

import { config } from "https://deno.land/x/[email protected]/mod.ts"

error: Import 'https://deno.land/x/[email protected]/mod.ts' failed: error sending request for url (https://deno.land/x/[email protected]/mod.ts): error trying to connect: Connection reset by peer (os error 104)

@dandv
Copy link

dandv commented Dec 16, 2024

@mwk24 Deno fails to resolve firestore.googleapis.com for me - #27384.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly web related to Web APIs
Projects
None yet
Development

No branches or pull requests