fix(stream): resume connection when stream errors or is destroyed #3775
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR continues #3769 work and fixes #3596. It also seems to resolve #1847 and resolve #1168, ensuring that
destroyand error events are properly issued (not usingtry-catch, butstream.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:
After this PR
Now all tests are reached:
Note
Thanks @fenichelar, @CarlOlson, and @dsech. Your examples and solutions helped us achieve a better understanding of the error 🤝