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

fix: add error when destroying stream to generate close event even when the network connection is down #713

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

pierreca
Copy link

@pierreca pierreca commented Nov 7, 2017

Fixes #710

When a stream is closed because the network connection, the close even fires correctly but after that if a user calls client.end() with a callback. that callback will never get called. As far as I understand, that is because the stream object will only fire another close event (which is required for the callback to be called) if stream.destroy(). is called with an error argument.

Tried to find a way to simulate the conditions in unit tests but could only repro the behavior with an actual network disconnection... so no specific test. existing tests don't seem to bother though.

@codecov
Copy link

codecov bot commented Nov 7, 2017

Codecov Report

Merging #713 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master    #713   +/-   ##
======================================
  Coverage    92.9%   92.9%           
======================================
  Files           8       8           
  Lines         705     705           
  Branches      171     171           
======================================
  Hits          655     655           
  Misses         50      50
Impacted Files Coverage Δ
lib/client.js 96.31% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5d4d295...34873ca. Read the comment docs.

@mcollina
Copy link
Member

mcollina commented Nov 8, 2017

A unit test would be really good at this point. You can at least add a test that checks that an 'error'  event is emitted on the stream.

@mcollina
Copy link
Member

mcollina commented Dec 9, 2017

Is there any update to this one?

@pierreca
Copy link
Author

@mcollina Sorry, slammed by work - I hope I can get back to that and add the test later, although I'm not sure I understand yet what exactly you think it'll test (I have to spend more time looking at it)

feel free to close if you don't like idling issues.

@mcollina
Copy link
Member

More or less I want a test that verified that 'error' is emitted on the stream if this.end(true) is passed in, and such callback is called.

Also, an example showing that such callback is indeed not called without this change.

@OmgImAlexis
Copy link
Contributor

@pierreca any chance on the conflicts being resolved? If not can this please be closed and the associated issue updated so someone else can take a stab at this.

@OmgImAlexis OmgImAlexis requested a review from mcollina May 13, 2020 04:41
@robertsLando
Copy link
Member

@pierreca Could you have another look at this please? I'm tring to keep this library updated and I'm looking at open PR to see if there are some that could be merged. This looks ok to me

@robertsLando robertsLando changed the title Add error when destroying stream to generate close event even when the network connection is down fix: add error when destroying stream to generate close event even when the network connection is down Jun 27, 2023
@robertsLando robertsLando requested review from robertsLando and removed request for mcollina June 27, 2023 12:53
@@ -1155,7 +1155,7 @@ MqttClient.prototype._cleanUp = function (forced, done) {
flush(this.outgoing)
}
debug('_cleanUp :: (%s) :: destroying stream', this.options.clientId)
this.stream.destroy()
this.stream.destroy(new Error('stream forcefully closed by the client'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test that reproduces the issue

@pierreca pierreca closed this Jun 27, 2023
@robertsLando robertsLando reopened this Jun 28, 2023
@robertsLando
Copy link
Member

It's not 100% clear to me why this happens. I mean based on nodejs docs the close event should be emitted every time destroy is called on a stream, it's just the error event that is emitted too if an error is passed. I keep this opened for now as I got some errors too in the past with client.end and I'm not sure if this could be a solution to that or nope

@robertsLando
Copy link
Member

also please move the PR to main instead of master

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.

None yet

4 participants