oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
71.09k stars 2.47k forks source link

Fetch Bug or Promise.all bug #10896

Open encu2 opened 1 week ago

encu2 commented 1 week ago

What version of Bun is running?

Bun v1.1.7 (Linux x64)

What platform is your computer?

Linux 6.1.75+ x86_64 x86_64

What steps can reproduce the bug?

i dont know where is bug come from, check my simple code below i hope u can find some interesting.

Bug no appear

const a = Array.from({ length: 5 }, () => fetch("https://wikipedia.org/")); await Promise.all(a);

note: when you set & run this code with length value <= 5, you wouldn't get some throw error, it will run normally.

Bug appear

const a = Array.from({ length: 6 }, () => fetch("https://wikipedia.org/")); await Promise.all(a);

note: Until i set it more than >= 6, it will throw some error like this,

FailedToOpenSocket: Was there a typo in the url or port? path: "https://wikipedia.org/"

it's really confusing, when someone in our comunity ask me to try use Promise.allSettled. Did you know what will happen? it's not throw any error and if i set length:100, it's not produce any error. All of the status codes are 200.

PICT OF ERR

Screenshot 2024-05-07 at 22-06-41 Welcome – proxy – Google Cloud console Screenshot 2024-05-07 at 22-09-04 Welcome – proxy – Google Cloud console Screenshot 2024-05-07 at 22-08-12 Welcome – proxy – Google Cloud console

Log Promise.allSettled

log.txt

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

soitchu commented 1 week ago

For what it's worth, I wasn't able to replicate this with v1.1.7 on Linux. Have you been able to replicate it for other URLs other than wikipedia.org?

encu2 commented 1 week ago

i was. I have whole junk of urls from my crawling tool and it still write in python. Here i just wanna re-write my code and search any aspect in bun to replicate my python code. But, there has some problem as u can see above.

Here, i just use wikipedia.org for simple explaination and use case. Then, if u get err from the most common url, it was something wrong with this bun fetch/Promise.all.

If u wanna test other use case, use this code below (use leaky.mjs). It from jarred. https://gist.github.com/Jarred-Sumner/bc5fc8e092f2036c396e8fb507a9f3c2

I was try this code and modify fetch to other urls, it still error but in random sequences. If you increase the batch like to 100, u will more often seeing this error "FailedToOpenSocket: Was there a typo in the url or port?". But u wouldn't get this error while u change Promise.all to Promise.allSettled like i was mentioned above.

soitchu commented 1 week ago

But u wouldn't get this error while u change Promise.all to Promise.allSettled like i was mentioned above.

That makes sense because Promise.allSettled never rejects. Going through the log file you attached, you can see that one of the promises did get rejected (this is on line 722):

{
    status: "rejected",
    reason: FailedToOpenSocket: Was there a typo in the url or port?
    path: "https://wikipedia.org/"
}

So Promise.allSettled wouldn't fail, but Promise.all will. So your issue most probably has to do with fetch rather than it being a Promise.all bug.

soitchu commented 1 week ago

Possibly a duplicate of #3327

encu2 commented 1 week ago

@soitchu sorry my bad, but in fact Promise.allSettled has higher limit than "Promise.all". Maybe next update they will fix it.

For possible duplicate, i'll say true, if talk about "fetch" problem. But, in my case & my opinion it get more distrubed while u unable send more than >6 fetch (in my case) request at the same time when set the array to Promise.all with just simple code test.