fix: invalid host message is missing on clientwith https (#3997) #3998
+130
−1
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.
For Bugs and Features; did you add new tests?
Added a new test that successfully fails with
client.terminate
Motivation / Use-Case
See #3997. When host/origin headers do not match,
client.terminate
was being called. However, when HTTPS is enabled, this message is encrypted asynchronously by NodeJS before it gets written to the socket. Therefore, whenclient.terminate
destroys the underlying socket the previoussendMessage
had not yet been written to the socket.Only applies when HTTPS is enabled.
Using
client.close
ensures that the socket is closed after all data is sent.Breaking Changes
None
Additional Info
Granted, with a bad client, this could leak forever as there is no timeout. However, I do not see timeouts elsewhere so they could be added as part of adding them elsewhere. It's also a development tool that is unlikely to be very long lived, and will be extremely easy to restart upon any issue (always attended), so it's likely timeouts would unnecessarily overcomplicate the implementation with little benefit.
I also fixed loads of warnings I was getting running tests about EventEmitter leaks due to the signal listener that is registered when creating an instance. I can remove this code from this commit if it's a problem - it seemed very minor and fine to add as part of same commit - and either omit it entirely or raise separately for you.
Fixes #3997