Skip to content

Commit 9ccf0e5

Browse files
committed
Don't error on ENOTCONN from shutdown()
1 parent dcc2dd5 commit 9ccf0e5

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

lib/http.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ Agent.prototype._establishNewConnection = function() {
11851185
parser.incoming = null;
11861186

11871187
socket.on('error', function(err) {
1188-
debug('AGENT SOCKET ERROR: ' + err.message);
1188+
debug('AGENT SOCKET ERROR: ' + err.message + '\n' + err.stack);
11891189
var req;
11901190
if (socket._httpMessage) {
11911191
req = socket._httpMessage;

lib/net.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,12 @@ Socket.prototype._shutdown = function() {
844844
try {
845845
this._shutdownImpl();
846846
} catch (e) {
847-
this.destroy(e);
847+
if (e.code == 'ENOTCONN') {
848+
// Allowed.
849+
this.destroy();
850+
} else {
851+
this.destroy(e);
852+
}
848853
}
849854
} else {
850855
// writable but not readable

test/disabled/GH-670.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
var assert = require('assert');
2+
var https = require('https');
3+
var tls = require('tls');
4+
5+
var options = {
6+
host: 'github.com',
7+
path: '/kriskowal/tigerblood/',
8+
port: 443
9+
};
10+
11+
var req = https.get(options, function(response) {
12+
var recved = 0;
13+
14+
response.on('data', function(chunk) {
15+
recved += chunk.length;
16+
console.log('Response data.');
17+
});
18+
19+
response.on('end', function() {
20+
console.log('Response end.');
21+
// Does not work
22+
loadDom();
23+
});
24+
25+
});
26+
27+
req.on('error', function(e) {
28+
console.log('Error on get.');
29+
});
30+
31+
function loadDom() {
32+
// Do a lot of computation to stall the process.
33+
// In the meantime the socket will be disconnected.
34+
for (var i = 0; i < 1e8; i++) {
35+
;
36+
}
37+
38+
console.log('Dom loaded.');
39+
}

0 commit comments

Comments
 (0)