Skip to content

Commit 8bc3a7c

Browse files
joamagLinusUjimmywarting
authoredJun 29, 2023
fix: socket variable testing for undefined (#1726)
* fix: socket variable testing for undefined Avoid issue where socket event was not triggered and local socket vraible is not defined. This issue is reproducible only using deno. * chore: made socket test capture simpler Only controls the execution of the section that uses socket. * Update src/index.js Co-authored-by: Linus Unnebäck <linus@folkdatorn.se> * Update index.js --------- Co-authored-by: Linus Unnebäck <linus@folkdatorn.se> Co-authored-by: Jimmy Wärting <jimmy@warting.se>
1 parent afb36f6 commit 8bc3a7c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed
 

‎src/index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,11 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
362362
const {headers} = response;
363363
if (headers['transfer-encoding'] === 'chunked' && !headers['content-length']) {
364364
response.once('close', hadError => {
365-
// if a data listener is still present we didn't end cleanly
366-
const hasDataListener = socket.listenerCount('data') > 0;
365+
// tests for socket presence, as in some situations the
366+
// the 'socket' event is not triggered for the request
367+
// (happens in deno), avoids `TypeError`
368+
// if a data listener is still present we didn't end cleanly
369+
const hasDataListener = socket && socket.listenerCount('data') > 0;
367370

368371
if (hasDataListener && !hadError) {
369372
const err = new Error('Premature close');

0 commit comments

Comments
 (0)
Please sign in to comment.