Skip to content

Commit

Permalink
Merge pull request #401 from tomas/remove-on-socket-end
Browse files Browse the repository at this point in the history
Remove on_socket_end callback
  • Loading branch information
tomas authored Apr 25, 2022
2 parents 8353cdb + f92aee8 commit e173397
Showing 1 changed file with 1 addition and 19 deletions.
20 changes: 1 addition & 19 deletions lib/needle.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,15 +575,6 @@ Needle.prototype.send_request = function(count, method, uri, config, post_data,
}, milisecs);
}

// handle errors on the underlying socket, that may be closed while writing
// for an example case, see test/long_string_spec.js. we make sure this
// scenario ocurred by verifying the socket's writable & destroyed states.
function on_socket_end() {
if (returned && !this.writable && this.destroyed === false) {
this.destroy();
had_error(new Error('Remote end closed socket abruptly.'))
}
}

debug('Making request #' + count, request_opts);
request = protocol.request(request_opts, function(resp) {
Expand Down Expand Up @@ -833,7 +824,7 @@ Needle.prototype.send_request = function(count, method, uri, config, post_data,
if (timer) clearTimeout(timer);
})

// handle socket 'end' event to ensure we don't get delayed EPIPE errors.
// set response timeout once we get a valid socket
request.once('socket', function(socket) {
if (socket.connecting) {
socket.once('connect', function() {
Expand All @@ -842,15 +833,6 @@ Needle.prototype.send_request = function(count, method, uri, config, post_data,
} else {
set_timeout('response', config.response_timeout);
}

// socket.once('close', function(e) {
// console.log('socket closed!', e);
// })

if (!socket.on_socket_end) {
socket.on_socket_end = on_socket_end;
socket.once('end', function() { process.nextTick(on_socket_end.bind(socket)) });
}
})

if (post_data) {
Expand Down

0 comments on commit e173397

Please sign in to comment.