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

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

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 3
  • Comments: 20 (6 by maintainers)

Most upvoted comments

I am getting this in an import statement:

import { config } from "https://deno.land/x/dotenv@v3.2.2/mod.ts"

error: Import ‘https://deno.land/x/dotenv@v3.2.2/mod.ts’ failed: error sending request for url (https://deno.land/x/dotenv@v3.2.2/mod.ts): error trying to connect: Connection reset by peer (os error 104)

@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.

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.

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

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