GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http: fix ClientRequest unhandled errors · nodejs/node@4cdc5ea

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • _http_client.js
  • test/parallel
    • test-http-client-abort3.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/_http_client.js‎

Copy file name to clipboardExpand all lines: lib/_http_client.js
+9-7Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -818,13 +818,15 @@ function onSocketNT(req, socket, err) {
818818
req.emit('close');
819819
}
820820

821-
if (!err && req.agent) {
822-
socket?.emit('free');
823-
} else if (socket) {
824-
finished(socket.destroy(err || req[kError]), (er) => {
825-
_destroy(req, er || err);
826-
});
827-
return;
821+
if (socket) {
822+
if (!err && req.agent && !socket.destroyed) {
823+
socket.emit('free');
824+
} else {
825+
finished(socket.destroy(err || req[kError]), (er) => {
826+
_destroy(req, er || err);
827+
});
828+
return;
829+
}
828830
}
829831

830832
_destroy(req, err || req[kError]);
Collapse file

‎test/parallel/test-http-client-abort3.js‎

Copy file name to clipboard
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const http = require('http');
5+
const net = require('net');
6+
7+
function createConnection() {
8+
const socket = new net.Socket();
9+
10+
process.nextTick(function() {
11+
socket.destroy(new Error('Oops'));
12+
});
13+
14+
return socket;
15+
}
16+
17+
{
18+
const req = http.get({ createConnection });
19+
20+
req.on('error', common.expectsError({ name: 'Error', message: 'Oops' }));
21+
req.abort();
22+
}
23+
24+
{
25+
class CustomAgent extends http.Agent {}
26+
CustomAgent.prototype.createConnection = createConnection;
27+
28+
const req = http.get({ agent: new CustomAgent() });
29+
30+
req.on('error', common.expectsError({ name: 'Error', message: 'Oops' }));
31+
req.abort();
32+
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.