-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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: socket variable testing for undefined #1726
Conversation
Avoid issue where socket event was not triggered and local socket vraible is not defined. This issue is reproducible only using deno.
@jimmywarting do you think you can merge this one? It's a simple undefined validation 🙏 |
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.
Yes it makes more sense. |
Co-authored-by: Linus Unnebäck <[email protected]>
@jimmywarting should be ready for merge 😀 |
@LinusU Can you the this PR, it would be super useful to have this one merged :) 🙏 |
🎉 This PR is included in version 2.6.12 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Including node-fetch as it should now be compatible with deno. According to node-fetch/node-fetch#1726.
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.