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

basic-ftp does not work properly in bun #10947

Open
eslym opened this issue May 9, 2024 · 0 comments
Open

basic-ftp does not work properly in bun #10947

eslym opened this issue May 9, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@eslym
Copy link

eslym commented May 9, 2024

What version of Bun is running?

1.1.7+b0b7db5c0

What platform is your computer?

Linux 5.15.146.1-microsoft-standard-WSL2 x86_64 unknown

What steps can reproduce the bug?

import { Client } from "basic-ftp";
import { PassThrough, Readable } from "stream";

const host = " some host here ";
const user = " some user here ";
const pass = " some password here ";
const file = " some file here ";

const client = new Client();
await client.connect(host);
await client.login(user, pass);
await client.useDefaultSettings();

async function test() {
  console.time("Finish");
  const pipe = new PassThrough();
  const size = await client.size(file);
  const readable = Readable.toWeb(pipe);

  let read = 0;
  pipe.on("data", (chunk) => {
    read += chunk.length;
    console.log(".reading:", chunk.length);
  });
  pipe.on("end", () => {
    console.log("Read:", read);
    console.timeEnd("Transfer");
  });

  console.log("Size:", size);
  const res = new Response(readable, {
    headers: {
      "Content-Length": size.toString(),
    },
  });

  console.time("Transfer");
  const [text] = await Promise.all([res.text(), client.downloadTo(pipe, file)]);

  console.log("Final Text:", text.length);

  console.timeEnd("Finish");
}

for (let i = 0; i < 5; i++) {
  console.log(`----- Attempt ${i + 1} -----`);
  await test();
}

client.close(); // Bun does not stop after this line while node does.

export {};

What is the expected behavior?

should be like running in nodejs (v20.12.2), the reading is complete, no weird long delay, process exit after connection close

$ node --experimental-loader=module test.js
(node:5622) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:
--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("module", pathToFileURL("./"));'
(Use `node --trace-warnings ...` to show where the warning was created)
----- Attempt 1 -----
Size: 4146
.reading: 4146
Read: 4146
Transfer: 50.346ms
Final Text: 4146
Finish: 104.405ms
----- Attempt 2 -----
Size: 4146
.reading: 4146
Read: 4146
Transfer: 49.993ms
Final Text: 4146
Finish: 80.264ms
----- Attempt 3 -----
Size: 4146
.reading: 4146
Read: 4146
Transfer: 53.298ms
Final Text: 4146
Finish: 89.71ms
----- Attempt 4 -----
Size: 4146
.reading: 4146
Read: 4146
Transfer: 51.585ms
Final Text: 4146
Finish: 88.152ms
----- Attempt 5 -----
Size: 4146
.reading: 4146
Read: 4146
Transfer: 49.484ms
Final Text: 4146
Finish: 80.072ms

What do you see instead?

$ bun --bun test.js
----- Attempt 1 -----
Size: 4146
.reading: 4146
Read: 4146
[58.89ms] Transfer
Final Text: 4146
[10.48s] Finish
----- Attempt 2 -----
Size: 4146
.reading: 4146
Read: 4146
[47.51ms] Transfer
Final Text: 4146
[10.47s] Finish
----- Attempt 3 -----
Size: 4146
Read: 0
[50.87ms] Transfer
Final Text: 0
[10.47s] Finish
----- Attempt 4 -----
Size: 4146
.reading: 4146
Read: 4146
[60.75ms] Transfer
Final Text: 4146
[10.48s] Finish
----- Attempt 5 -----
Size: 4146
.reading: 4146
Read: 4146
[49.39ms] Transfer
Final Text: 4146
[10.46s] Finish
^C
  1. sometimes read nothing (or only read partially)
  2. weird long delay between transfer finish and task finish
  3. process not stop after connection close (need to Ctrl + C manually)

Additional information

  1. i think there is multiple issues regarding tcp in this issue, mysql2 also seems to not stopping the process after closing the connection.
  2. Windows version of bun is even worse.
Result on windows

Microsoft Windows NT 10.0.22631.0 x64
Bun 1.1.7+b0b7db5c0

> bun --bun test.js
----- Attempt 1 -----
Size: 4146
Read: 0
[70.48ms] Transfer
Final Text: 0
[10.50s] Finish
----- Attempt 2 -----
Size: 4146
Read: 0
[66.35ms] Transfer
Final Text: 0
[10.49s] Finish
----- Attempt 3 -----
Size: 4146
Read: 0
[62.46ms] Transfer
Final Text: 0
[10.49s] Finish
----- Attempt 4 -----
Size: 4146
Read: 0
[54.47ms] Transfer
Final Text: 0
[10.49s] Finish
----- Attempt 5 -----
Size: 4146
Read: 0
[53.33ms] Transfer
Final Text: 0
[10.49s] Finish

Nothing read

@eslym eslym added the bug Something isn't working label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant