Skip to content

Commit

Permalink
Merge pull request #263 from tomas/fix-socket-destroy-on-redirect
Browse files Browse the repository at this point in the history
Right way to fix the socket.destroy issue (Node v8.12.0)
  • Loading branch information
tomas authored Sep 22, 2018
2 parents 942b3e4 + f2a017b commit c6cc884
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions lib/needle.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,7 @@ Needle.prototype.send_request = function(count, method, uri, config, post_data,
// 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() {
// socket.ssl is present on node versions 8.12.0, where the socket.destroy
// logic was apparently fixed.
if (!this.writable && this.destroyed === false && !this.ssl) {
if (!this.writable && this.destroyed === false) {
this.destroy();
had_error(new Error('Remote end closed socket abruptly.'))
}
Expand Down Expand Up @@ -714,9 +712,10 @@ Needle.prototype.send_request = function(count, method, uri, config, post_data,
set_timeout('response', config.response_timeout);
}

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

Expand Down
2 changes: 1 addition & 1 deletion test/long_string_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('when posting a very long string', function() {
}

try {
needle.post('http://google.com', { data: get_string(Math.pow(2, 20)) }, finished)
needle.post('https://google.com', { data: get_string(Math.pow(2, 20)) }, finished)
} catch(e) {
error = e;
}
Expand Down

0 comments on commit c6cc884

Please sign in to comment.