Skip to content
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

Remove on_socket_end callback #401

Merged
merged 1 commit into from
Apr 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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