fix: socket variable testing for undefined#1726
Merged
jimmywarting merged 4 commits intonode-fetch:2.xfrom Jun 29, 2023
joamag:2.x
Merged
fix: socket variable testing for undefined#1726jimmywarting merged 4 commits intonode-fetch:2.xfrom joamag:2.x
jimmywarting merged 4 commits intonode-fetch:2.xfrom
joamag:2.x
Conversation
Avoid issue where socket event was not triggered and local socket vraible is not defined. This issue is reproducible only using deno.
Author
|
@jimmywarting do you think you can merge this one? It's a simple undefined validation 🙏 |
Collaborator
request.on('response', response => {
const {headers} = response;
if (headers['transfer-encoding'] === 'chunked' && !headers['content-length']) {
response.once('close', hadError => {
// if for some reason the 'socket' event was not triggered
// for the request (happens in deno) avoids `TypeError`
if (socket === undefined) {
return;
}
// if a data listener is still present we didn't end cleanly
const hasDataListener = socket.listenerCount('data') > 0;
if (hasDataListener && !hadError) {
const err = new Error('Premature close');
err.code = 'ERR_STREAM_PREMATURE_CLOSE';
errorCallback(err);
}
});
}
});don't we still want to handle if (hasDataListener && !hadError) {
const err = new Error('Premature close');
err.code = 'ERR_STREAM_PREMATURE_CLOSE';
errorCallback(err);
}maybe would be better to just do: // if for some reason the 'socket' event was not triggered
// for the request (happens in deno) avoids `TypeError`
if (socket) {
// if a data listener is still present we didn't end cleanly
const hasDataListener = socket.listenerCount('data') > 0;
} |
Only controls the execution of the section that uses socket.
Author
Yes it makes more sense. |
LinusU
reviewed
May 17, 2023
Co-authored-by: Linus Unnebäck <linus@folkdatorn.se>
Author
|
@jimmywarting should be ready for merge 😀 |
Author
|
@LinusU Can you the this PR, it would be super useful to have this one merged :) 🙏 |
jimmywarting
approved these changes
Jun 29, 2023
|
🎉 This PR is included in version 2.6.12 🎉 The release is available on: Your semantic-release bot 📦🚀 |
joamag
added a commit
to hivesolutions/yonius
that referenced
this pull request
Oct 25, 2023
Including node-fetch as it should now be compatible with deno. According to node-fetch/node-fetch#1726.
This was referenced May 19, 2024
This was referenced May 20, 2024
This was referenced Sep 23, 2024
This was referenced Sep 25, 2024
This was referenced Sep 30, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Avoid issue where socket event was not triggered and local socket variable is not defined. This issue is reproducible only using deno.
Purpose
#1725
Changes
Adds undefined testing to socket variable, protecting it from TypeError.