nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
106.52k stars 29.03k forks source link

The `opendir` function returned an incorrect result. #54315

Open magic-akari opened 1 month ago

magic-akari commented 1 month ago

Version

v20.15.1

Platform

Darwin akari-MacBook-Pro.local 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6000 arm64

Subsystem

No response

What steps will reproduce the bug?

opendir-wrong-result-0.0.0.tgz

Download the package and execute the command node list.mjs | wc.

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

Always

What is the expected behavior? Why is that the expected behavior?

Should print 465

What do you see instead?

Printed 188

Additional information

Code:

import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";

const data = fileURLToPath(new URL("./test_data", import.meta.url));

const dir = await fs.opendir(data, { recursive: true });
for await (const dirent of dir) {
    if (!dirent.isFile()) {
        continue;
    }
    console.log(path.join(dirent.parentPath, dirent.name));
}

It may be related to the bufferSize. Adjusting the bufferSize to 500 resulted in the correct output being printed.

- const dir = await fs.opendir(data, { recursive: true });
+ const dir = await fs.opendir(data, { recursive: true, bufferSize: 500 });
aduh95 commented 1 month ago

Thanks for filling the issue. If you're able to post a repro that does not involve downloading code from the internet, you're more likely to get help. Ideally, a list of commands that one can copy paste in their terminal.

sjohannes commented 3 hours ago

This seems to be the same as https://github.com/nodejs/node/issues/48820.

RedYetiDev commented 8 minutes ago

This seems to be the same as #48820.

@mdouglass is this the same as the issue you reported?