bun icon indicating copy to clipboard operation
bun copied to clipboard

fetch() fails on "https://jamsocket.xyz" (doesn't fail on node/deno/curl)

Open pretentious7 opened this issue 3 years ago • 17 comments
trafficstars

Version

0.1.13

Platform

Linux 5.15.0-47-generic #51-Ubuntu SMP Thu Aug 11 07:51:15 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

What steps will reproduce the bug?

(async () => {
try {
  console.log(await fetch("https://jamsocket.xyz"))
} catch(e) {
  console.error(e)
}
})()

export {}

(wrapped the async in a function for easier verification in node)

How often does it reproduce? Is there a required condition?

every time

What is the expected behavior?

Response (<<NOT SURE>> KB) {
  ok: true,
  url: "https://jamsocket.xyz/",
  statusText: "OK",
  redirected: false,
  bodyUsed: true,
  status: 200,
  Blob (<<NOT SURE>> KB)
}

What do you see instead?

ConnectionClosed: fetch() failed
 path: "https://jamsocket.xyz"

Additional information

No response

pretentious7 avatar Sep 20 '22 17:09 pretentious7

There is something strange happening with TLS and I don't understand what it is yet

It's definitely something to do with TLS 1.3.

Jarred-Sumner avatar Sep 21 '22 04:09 Jarred-Sumner

Maybe it's tickets

Jarred-Sumner avatar Sep 21 '22 04:09 Jarred-Sumner

Seems like it's definitely TLS 1.3 - another reproducible host where is happening: https://api.flexpa.com/config

try {
  await fetch('https://api.flexpa.com/config').then((response) => {
    if (!response.ok) {
      throw new Error(`HTTP error! Status: ${response.status}`);
    }

    return response.blob();
  })
} catch(e) {
  console.log(e)
}

Unexpectedly returns

ConnectionClosed: fetch() failed
 path: "https://api.flexpa.com/config"

jdjkelly avatar Sep 27 '22 04:09 jdjkelly

I am facing the same issue with the Notion api. I noticed the need repro label, @Jarred-Sumner; what exactly would you like to see (given the example from the OP is pretty straight forward?)

klaascuvelier avatar Sep 27 '22 08:09 klaascuvelier

At least on version 0.1.11 fetch was working flawlessly. I'm not sure when it happened, but on version 0.1.13 one of my working requests is now throwing ConnectionClosed: fetch() failed.

0x4a61636f62 avatar Oct 02 '22 17:10 0x4a61636f62

@jastraberg what specific website? It could be an issue with the BoringSSL handshake process which has different code now. If you can link to the specific website / repro, I can debug this

The broader TLS 1.3 issue needs to be fixed but I'm not really sure how yet.

Jarred-Sumner avatar Oct 02 '22 18:10 Jarred-Sumner

@Jarred-Sumner I have made a private repo https://github.com/jastraberg /repro-1263 and added you as a collaborator.

  • All of the relevant code is found in the directory: ./src/modules/api/classes/rest-client.class.ts
  • The entry point is main.ts in the root folder and can be run with bun run paper .
  • The endpoints/website are found in ./src/modules/api/constants/endpoints.constant.ts.

0x4a61636f62 avatar Oct 03 '22 13:10 0x4a61636f62

Any updates on this? Or any temporary workaround?

renhiyama avatar Oct 05 '22 10:10 renhiyama

This problem has my bun project suspended... so any updates/workarounds/... would be very welcome.

blackfyre avatar Oct 06 '22 08:10 blackfyre

I have a fix shortly.

Jarred-Sumner avatar Oct 08 '22 07:10 Jarred-Sumner

When moving to uSockets for the http client, I forgot to call SSL_set_tlsext_host_name and uSockets apparently doesn't do that. I'm sad this took 18 days to fix

Jarred-Sumner avatar Oct 08 '22 08:10 Jarred-Sumner

Welcome to failure management! (It's a meme, not roasting you ofc, just making you less stressful Jarred!)

renhiyama avatar Oct 11 '22 17:10 renhiyama

Experiencing the same error with 0.3.0 when trying to fetch https://unicode.org/Public/emoji/15.0/emoji-test.txt

cyberalien avatar Dec 16 '22 13:12 cyberalien

@robobun

await fetch("https://unicode.org/Public/emoji/15.0/emoji-test.txt");

Electroid avatar Dec 16 '22 17:12 Electroid

@Electroid here you go!

ConnectionClosed: fetch() failed
 path: "https://unicode.org/Public/emoji/15.0/emoji-test.txt"
Code
await fetch("https://unicode.org/Public/emoji/15.0/emoji-test.txt");

Ran using the latest build of Bun, an all-in-one JavaScript runtime.

robobun avatar Dec 16 '22 17:12 robobun

Spent some time investigating this

The behavior we're seeing is:

  1. We send a request like this:
GET /Public/emoji/15.0/emoji-test.txt
	accept-encoding: identity
	Connection: keep-alive
	User-Agent: Bun/0.4.1_debug
	Accept: */*
	Host: unicode.org
  1. It returns a Response like this:
< 	Date: Tue, 17 Jan 2023 01:19:25 GMT
< 	Server: Apache/2.4.38 (Debian)
< 	Content-Security-Policy: upgrade-insecure-requests;
< 	Last-Modified: Tue, 16 Aug 2022 16:34:20 GMT
< 	ETag: "90d58-5e65e5205627e"
< 	Accept-Ranges: bytes
< 	Content-Length: 593240
< 	Vary: Accept-Encoding
< 	Connection: close
< 	Content-Type: text/plain; charset=utf-8
  1. It includes the first 300-400 bytes, then the server closes the connection.

What I'm wondering here is: is it possible that uSockets is closing the socket before reading the data?

Jarred-Sumner avatar Jan 17 '23 01:01 Jarred-Sumner

@Jarred-Sumner here you go!

error: Expected identifier after "Date:" in namespaced JSX name
         Tue, 17 Jan 2023 01:19:25 GMT
/tmp/bun-
/tmp/bun-XB5i4K/index.js:1:9 8
Code
< 	Date: Tue, 17 Jan 2023 01:19:25 GMT
< 	Server: Apache/2.4.38 (Debian)
< 	Content-Security-Policy: upgrade-insecure-requests;
< 	Last-Modified: Tue, 16 Aug 2022 16:34:20 GMT
< 	ETag: "90d58-5e65e5205627e"
< 	Accept-Ranges: bytes
< 	Content-Length: 593240
< 	Vary: Accept-Encoding
< 	Connection: close
< 	Content-Type: text/plain; charset=utf-8

Ran using the latest build of Bun, an all-in-one JavaScript runtime.

robobun avatar Jan 17 '23 01:01 robobun

Fixed between Bun v0.5.9 and Bun v0.6.2

bun on  main
❯ cat /tmp/abc.ts
───────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: /tmp/abc.ts
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ await fetch("https://unicode.org/Public/emoji/15.0/emoji-test.txt");
───────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────

bun on  main
❯ bun-0.5.9 /tmp/abc.ts
ConnectionClosed: The socket connection was closed unexpectedly. For more information, pass `verbose: true` in the second argument to fetch()
 path: "https://unicode.org/Public/emoji/15.0/emoji-test.txt"

bun on  main
❯ bun-0.6.2 /tmp/abc.ts

Jarred-Sumner avatar Jul 31 '23 13:07 Jarred-Sumner