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

npm:undici fetch() fails to resolve with large buffer #28590

Open
AFKBETO opened this issue Mar 21, 2025 · 1 comment · May be fixed by #28600
Open

npm:undici fetch() fails to resolve with large buffer #28590

AFKBETO opened this issue Mar 21, 2025 · 1 comment · May be fixed by #28600
Labels
node API Related to various "node:*" modules APIs streams

Comments

@AFKBETO
Copy link

AFKBETO commented Mar 21, 2025

Hi, I have encountered a problem with undici on Deno.

When use undici's fetch() method to fetch a file sufficiently large, the promise fails to resolve. This is not the case on node.js. You can reproduce this issue through the following codes:

import { Buffer } from "node:buffer";
import { fetch } from 'undici';

const url = ''; // url for a remote file/image

if (import.meta.main) {

	const result = await fetch(url);
	const arr = await result.arrayBuffer();

	console.log(arr);

	const buffer = Buffer.from(arr);
	console.log(buffer);
}

With an image of ~40kB, this code fails to run on deno:
Image

Tested ok with a 2-3kB image:
Image

Version:

  • Deno 2.2.5
  • v8 13.5.212.4-rusty
  • typescript 5.7.3
  • Windows 11

Test image:
Big image (~40kB) and fail:
Image
Small image (~2kB) and success:
Image

The original issue is here: discordjs/discord.js#10812

@WWRS
Copy link

WWRS commented Mar 22, 2025

https://github.com/nodejs/undici/blob/2df904f4e7e79d878b60d9399704c6aa61af5453/lib/web/fetch/index.js#L1094

finished(internalResponse.body.stream, () => {

is silently throwing the error

TypeError [ERR_INVALID_ARG_TYPE]: The "stream" argument must be an instance of Stream. Received an instance of ReadableStream
    at eos (ext:deno_node/_stream.mjs:855:15)
    at fetchFinale (file:///.../node_modules/undici/lib/web/fetch/index.js:1094:9)
    ...

Avoiding this error seems to fix the issue.

Node checks in eos if the passed stream is a web stream or a Node stream: https://github.com/nodejs/node/blob/ffc1cf620550180b2192cba9a4785a06075e5b6f/lib/internal/streams/end-of-stream.js#L68

@littledivy littledivy added node API Related to various "node:*" modules APIs streams labels Mar 24, 2025
littledivy added a commit to littledivy/deno that referenced this issue Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
node API Related to various "node:*" modules APIs streams
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants