Skip to content

Conversation

@fenichelar
Copy link
Contributor

@fenichelar fenichelar commented Aug 26, 2025

When a stream errors (due to break, throw, etc.) the connection can remain paused indefinitely.

To reproduce, create table test with 500 rows and run the below. The script will never exit.

import { createPool } from 'mysql2';

const pool = createPool({
  database: 'test',
  host: '127.0.0.1',
  port: 3306,
  user: 'user',
});

const results = pool.query('select * from test;').stream();
for await (const result of results) {
  break;
}

pool.end();

See #3596

@fenichelar fenichelar changed the title Destroy connection when stream is destroyed Destroy connection when stream errors Aug 26, 2025
@codecov
Copy link

codecov bot commented Aug 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.20%. Comparing base (9c51eb9) to head (cbb211c).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3769      +/-   ##
==========================================
+ Coverage   89.09%   89.20%   +0.10%     
==========================================
  Files          86       86              
  Lines       13546    13549       +3     
  Branches     1573     1576       +3     
==========================================
+ Hits        12069    12086      +17     
+ Misses       1477     1463      -14     
Flag Coverage Δ
compression-0 89.20% <100.00%> (+0.10%) ⬆️
compression-1 89.20% <100.00%> (+0.10%) ⬆️
static-parser-0 86.76% <100.00%> (+0.10%) ⬆️
static-parser-1 87.53% <100.00%> (+0.10%) ⬆️
tls-0 88.61% <100.00%> (+0.10%) ⬆️
tls-1 88.86% <66.66%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wellwelwel wellwelwel linked an issue Aug 26, 2025 that may be closed by this pull request
@wellwelwel
Copy link
Collaborator

Thanks, @fenichelar! I'll test locally by forcing an error and check the feasibility of including your example as a test 🙋🏻‍♂️

@fenichelar
Copy link
Contributor Author

@wellwelwel test added.

@wellwelwel wellwelwel self-requested a review August 27, 2025 03:47
@wellwelwel wellwelwel changed the title Destroy connection when stream errors fix: destroy connection when stream errors Aug 27, 2025
@wellwelwel wellwelwel merged commit cc34a83 into sidorares:master Aug 27, 2025
100 checks passed
@wellwelwel
Copy link
Collaborator

Thanks again, @fenichelar! It's already available in mysql2@canary and soon in the latest version too 🤝

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Streaming pipeline errors block connections

2 participants