Skip to content

fix(stream): resume connection when stream errors or is destroyed - #3775

Merged
wellwelwel merged 8 commits into
sidorares:masterfrom
wellwelwel:stream
Aug 27, 2025
Merged

fix(stream): resume connection when stream errors or is destroyed#3775
wellwelwel merged 8 commits into
sidorares:masterfrom
wellwelwel:stream

Conversation

@wellwelwel

@wellwelwel wellwelwel commented Aug 27, 2025

Copy link
Copy Markdown
Collaborator

This PR continues #3769 work and fixes #3596. It also seems to resolve #1847 and resolve #1168, ensuring that destroy and error events are properly issued (not using try-catch, but stream.on('error', () => {}) approach, which is the expected pattern for callbacks).


In #3769, it destroys the connection on error to ensure that the stack is not blocked, but this approach can be aggressive, as a query error shouldn't destroy the connection.

In this PR, the approach is to destroy the current stream itself on error and emits the appropriate events, ensuring its functionality and allowing users to catch errors that were not previously emitted, as reported in #1847.


Before this PR

The test that checks the events is not reached and the script is silently ended prematurely:

Screenshot 2025-08-27 at 05 37 42

After this PR

Now all tests are reached:

Screenshot 2025-08-27 at 05 35 54

Note

Thanks @fenichelar, @CarlOlson, and @dsech. Your examples and solutions helped us achieve a better understanding of the error 🤝

@codecov

codecov Bot commented Aug 27, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.23%. Comparing base (69c1122) to head (fb8dbba).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3775      +/-   ##
==========================================
+ Coverage   89.20%   89.23%   +0.03%     
==========================================
  Files          86       86              
  Lines       13549    13583      +34     
  Branches     1576     1585       +9     
==========================================
+ Hits        12086    12121      +35     
+ Misses       1463     1462       -1     
Flag Coverage Δ
compression-0 89.23% <100.00%> (+0.03%) ⬆️
compression-1 89.23% <100.00%> (+0.03%) ⬆️
static-parser-0 86.80% <100.00%> (+0.04%) ⬆️
static-parser-1 87.57% <100.00%> (+0.03%) ⬆️
tls-0 88.65% <100.00%> (+0.03%) ⬆️
tls-1 89.00% <100.00%> (+0.14%) ⬆️

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.

Comment thread lib/commands/query.js Outdated
@wellwelwel
wellwelwel merged commit 9642a1e into sidorares:master Aug 27, 2025
100 checks passed
@wellwelwel
wellwelwel deleted the stream branch August 27, 2025 12:40
mdierolf pushed a commit to CloudQuote/node-mysql2 that referenced this pull request May 23, 2026
…dorares#3775)

* fix(stream): resume connection when stream errors or is destroyed

* fix: remove listeners when stream is destroyed

* ci: remove unreachable logic

* chore: remove stream listener when it is destroyed

* chore: ensure the error is emitted

* chore: TOC

* refactor: use native `close` and auto detroy

* refactor: follow ESLint rules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants