denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
98.05k stars 5.39k forks source link

Bug?: fetch(): Uncaught TypeError: error reading a body from connection #25992

Open akku1139 opened 1 month ago

akku1139 commented 1 month ago

Version: Deno 1.46.3

I have a problem when fetching this URL.

http(s)://www.astroarts.co.jp/article/feed.atom

> await (await fetch("http://www.astroarts.co.jp/article/feed.atom")).text()
Uncaught TypeError: error reading a body from connection
    at async readableStreamCollectIntoUint8Array (ext:deno_web/06_streams.js:1066:19)
    at async consumeBody (ext:deno_fetch/22_body.js:254:9)
    at async <anonymous>:1:22
> await (await fetch("https://www.astroarts.co.jp/article/feed.atom")).text()
Uncaught TypeError: error reading a body from connection
    at async readableStreamCollectIntoUint8Array (ext:deno_web/06_streams.js:1066:19)
    at async consumeBody (ext:deno_fetch/22_body.js:254:9)
    at async <anonymous>:1:22

The two below can be executed without any problems.

await (await fetch("http://www.astroarts.co.jp/")).text()
await (await fetch("https://www.astroarts.co.jp/")).text()

You can see that it has been loaded halfway.

> const stream = (await fetch("https://www.astroarts.co.jp/article/feed.atom")).body
undefined
> for await (const chunk of stream) { console.log(chunk) }
Uint8Array(64) [
   60,  63, 120, 109, 108,  32, 118, 101, 114, 115, 105,
  111, 110,  61,  34,  49,  46,  48,  34,  32, 101, 110,
   99, 111, 100, 105, 110, 103,  61,  34,  85,  84,  70,
   45,  56,  34,  63,  62,  10,  60, 102, 101, 101, 100,
   32, 120, 109, 108, 110, 115,  61,  34, 104, 116, 116,
  112,  58,  47,  47, 119, 119, 119,  46, 119
]
Uint8Array(64) [
   51,  46, 111, 114, 103,  47,  50,  48,  48,  53,  47,
   65, 116, 111, 109,  34,  62,  10,  32,  32,  60,  97,
// -------------- many lines ----------------
Uint8Array(64) [
  136,  49,  48, 230, 151, 165, 227, 129, 148, 227, 130,
  141, 227, 128, 130,  60,  47, 115, 117, 109, 109,  97,
  114, 121,  62,  10,  32,  32,  32,  32,  60, 117, 112,
  100,  97, 116, 101, 100,  62,  50,  48,  50,  52,  45,
   48,  57,  45,  48,  51,  84,  48,  57,  58,  49,  48,
   58,  50,  51,  90,  60,  47, 117, 112, 100
]
Uint8Array(25) [
   97, 116, 101, 100,  62,  10,  32,
   32,  60,  47, 101, 110, 116, 114,
  121,  62,  10,  60,  47, 102, 101,
  101, 100,  62,  10
]
Uncaught TypeError: error reading a body from connection
    at async Object.pull (ext:deno_web/06_streams.js:938:27)
lucacasonato commented 1 month ago

This looks like a poorly behaved server - node also fails when fetching this URL. curl can handle the URL though, so I am going to classify this as a bug.

akku1139 commented 1 month ago

fetch was successful in the Firefox 128 dev tools console and Bun.