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

connection.stream does not close in Bun #2884

Closed
steelywing opened this issue Jul 24, 2024 · 6 comments
Closed

connection.stream does not close in Bun #2884

steelywing opened this issue Jul 24, 2024 · 6 comments

Comments

@steelywing
Copy link

steelywing commented Jul 24, 2024

I cannot confirm this is Bun bug or mysql2 bug

Reproduce:

// Get the client
import mysql from 'mysql2/promise';

// Create the connection to database
const connection = mysql.createConnection({
    host: 'localhost',
    user: 'test',
    password: 'password',
    database: 'test',
});

try {
} catch (err) {
    console.log(err);
} finally {
    // this does not call `connection.stream.end()` in Bun
    await connection.end();
}

console.log("end");

// if comment out this line, `stream.end()` does not be called in Bun, 
// so Bun will not exit, but node.js will exit normally
connection.connection.close();

the doc says we only need to call connection.end(), but that function does not end the net stream in Bun

Related: oven-sh/bun#11414

@wellwelwel wellwelwel added the bun label Jul 24, 2024
@wellwelwel
Copy link
Collaborator

wellwelwel commented Jul 24, 2024

Hi, @steelywing. Thanks for the report.

This issue is reflected in MySQL2 internal tests too:

connection.end((err) => {
assert.ifError(err);
process.exit(0);
});

  • Note the need to use process.exit(0).

I haven't had time to check whether this should be an error to be reported in Bun or handled directly in MySQL2.

However, in the short research I've done, this seems to be related to the way Bun handles callbacks.

@wellwelwel wellwelwel added the bug label Jul 24, 2024
@Tanavya
Copy link

Tanavya commented Aug 8, 2024

Is this related to my issue? oven-sh/bun#12155

@wellwelwel
Copy link
Collaborator

@wellwelwel
Copy link
Collaborator

wellwelwel commented Aug 8, 2024

Unfortunately, I can't see which version of Bun started this, but this error was introduced later (before some specific version, it worked normally).

Looking at what has changed in this version could help clarify what happened (some Bun release around 24/01/18).

@steelywing
Copy link
Author

steelywing commented Aug 9, 2024

I found the cause is if socket is FIN from the other side, the Socket will not exit.

I have a question from this code, is it better call stream.end() even if it is client:

end(callback) {

@wellwelwel
Copy link
Collaborator

@steelywing, it seems that Bun has fixed this bug in oven-sh/bun#13212.

After they release it, I'll revisit MySQL2 tests 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants