| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d3070d8 commit 80ce97f
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -284,7 +284,6 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */, | |||
| 284 | 284 | this.reuseSocket(socket, req); | |
| 285 | 285 | setRequestSocket(this, req, socket); | |
| 286 | 286 | ArrayPrototypePush(this.sockets[name], socket); | |
| 287 | - this.totalSocketCount++; | ||
| 288 | 287 | } else if (sockLen < this.maxSockets && | |
| 289 | 288 | this.totalSocketCount < this.maxTotalSockets) { | |
| 290 | 289 | debug('call onSocket', sockLen, freeLen); | |
@@ -383,6 +382,7 @@ function installListeners(agent, s, options) { | |||
| 383 | 382 | // This is the only place where sockets get removed from the Agent. | |
| 384 | 383 | // If you want to remove a socket from the pool, just close it. | |
| 385 | 384 | // All socket errors end in a close event anyway. | |
| 385 | + agent.totalSocketCount--; | ||
| 386 | 386 | agent.removeSocket(s, options); | |
| 387 | 387 | } | |
| 388 | 388 | s.on('close', onClose); | |
@@ -406,6 +406,7 @@ function installListeners(agent, s, options) { | |||
| 406 | 406 | // (defined by WebSockets) where we need to remove a socket from the | |
| 407 | 407 | // pool because it'll be locked up indefinitely | |
| 408 | 408 | debug('CLIENT socket onRemove'); | |
| 409 | + agent.totalSocketCount--; | ||
| 409 | 410 | agent.removeSocket(s, options); | |
| 410 | 411 | s.removeListener('close', onClose); | |
| 411 | 412 | s.removeListener('free', onFree); | |
@@ -438,7 +439,6 @@ Agent.prototype.removeSocket = function removeSocket(s, options) { | |||
| 438 | 439 | // Don't leak | |
| 439 | 440 | if (sockets[name].length === 0) | |
| 440 | 441 | delete sockets[name]; | |
| 441 | - this.totalSocketCount--; | ||
| 442 | 442 | } | |
| 443 | 443 | } | |
| 444 | 444 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -59,6 +59,7 @@ function checkDataAndSockets(body) { | |||
| 59 | 59 | assert.strictEqual(body.toString(), 'hello world'); | |
| 60 | 60 | assert.strictEqual(agent.sockets[name].length, 1); | |
| 61 | 61 | assert.strictEqual(agent.freeSockets[name], undefined); | |
| 62 | + assert.strictEqual(agent.totalSocketCount, 1); | ||
| 62 | 63 | } | |
| 63 | 64 | ||
| 64 | 65 | function second() { | |
@@ -73,6 +74,7 @@ function second() { | |||
| 73 | 74 | process.nextTick(common.mustCall(() => { | |
| 74 | 75 | assert.strictEqual(agent.sockets[name], undefined); | |
| 75 | 76 | assert.strictEqual(agent.freeSockets[name].length, 1); | |
| 77 | + assert.strictEqual(agent.totalSocketCount, 1); | ||
| 76 | 78 | remoteClose(); | |
| 77 | 79 | })); | |
| 78 | 80 | })); | |
@@ -91,10 +93,12 @@ function remoteClose() { | |||
| 91 | 93 | process.nextTick(common.mustCall(() => { | |
| 92 | 94 | assert.strictEqual(agent.sockets[name], undefined); | |
| 93 | 95 | assert.strictEqual(agent.freeSockets[name].length, 1); | |
| 96 | + assert.strictEqual(agent.totalSocketCount, 1); | ||
| 94 | 97 | // Waiting remote server close the socket | |
| 95 | 98 | setTimeout(common.mustCall(() => { | |
| 96 | 99 | assert.strictEqual(agent.sockets[name], undefined); | |
| 97 | 100 | assert.strictEqual(agent.freeSockets[name], undefined); | |
| 101 | + assert.strictEqual(agent.totalSocketCount, 0); | ||
| 98 | 102 | remoteError(); | |
| 99 | 103 | }), common.platformTimeout(200)); | |
| 100 | 104 | })); | |
@@ -110,10 +114,12 @@ function remoteError() { | |||
| 110 | 114 | assert.strictEqual(err.message, 'socket hang up'); | |
| 111 | 115 | assert.strictEqual(agent.sockets[name].length, 1); | |
| 112 | 116 | assert.strictEqual(agent.freeSockets[name], undefined); | |
| 117 | + assert.strictEqual(agent.totalSocketCount, 1); | ||
| 113 | 118 | // Wait socket 'close' event emit | |
| 114 | 119 | setTimeout(common.mustCall(() => { | |
| 115 | 120 | assert.strictEqual(agent.sockets[name], undefined); | |
| 116 | 121 | assert.strictEqual(agent.freeSockets[name], undefined); | |
| 122 | + assert.strictEqual(agent.totalSocketCount, 0); | ||
| 117 | 123 | server.close(); | |
| 118 | 124 | }), common.platformTimeout(1)); | |
| 119 | 125 | })); | |
@@ -132,6 +138,7 @@ server.listen(0, common.mustCall(() => { | |||
| 132 | 138 | process.nextTick(common.mustCall(() => { | |
| 133 | 139 | assert.strictEqual(agent.sockets[name], undefined); | |
| 134 | 140 | assert.strictEqual(agent.freeSockets[name].length, 1); | |
| 141 | + assert.strictEqual(agent.totalSocketCount, 1); | ||
| 135 | 142 | second(); | |
| 136 | 143 | })); | |
| 137 | 144 | })); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -61,7 +61,12 @@ server.listen(0, '127.0.0.1', common.mustCall(function() { | |||
| 61 | 61 | const req = http.request(options); | |
| 62 | 62 | req.end(); | |
| 63 | 63 | ||
| 64 | + req.on('socket', common.mustCall(function() { | ||
| 65 | + assert.strictEqual(req.agent.totalSocketCount, 1); | ||
| 66 | + })); | ||
| 67 | + | ||
| 64 | 68 | req.on('upgrade', common.mustCall(function(res, socket, upgradeHead) { | |
| 69 | + assert.strictEqual(req.agent.totalSocketCount, 0); | ||
| 65 | 70 | let recvData = upgradeHead; | |
| 66 | 71 | socket.on('data', function(d) { | |
| 67 | 72 | recvData += d; | |
@@ -71,14 +76,13 @@ server.listen(0, '127.0.0.1', common.mustCall(function() { | |||
| 71 | 76 | assert.strictEqual(recvData.toString(), 'nurtzo'); | |
| 72 | 77 | })); | |
| 73 | 78 | ||
| 74 | - console.log(res.headers); | ||
| 75 | 79 | const expectedHeaders = { 'hello': 'world', | |
| 76 | 80 | 'connection': 'upgrade', | |
| 77 | 81 | 'upgrade': 'websocket' }; | |
| 78 | 82 | assert.deepStrictEqual(expectedHeaders, res.headers); | |
| 79 | 83 | ||
| 80 | 84 | // Make sure this request got removed from the pool. | |
| 81 | - assert(!(name in http.globalAgent.sockets)); | ||
| 85 | + assert(!(name in req.agent.sockets)); | ||
| 82 | 86 | ||
| 83 | 87 | req.on('close', common.mustCall(function() { | |
| 84 | 88 | socket.end(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -82,7 +82,6 @@ server.listen(0, common.mustCall(function() { | |||
| 82 | 82 | assert.strictEqual(recvData.toString(), expectedRecvData); | |
| 83 | 83 | })); | |
| 84 | 84 | ||
| 85 | - console.log(res.headers); | ||
| 86 | 85 | const expectedHeaders = { | |
| 87 | 86 | hello: 'world', | |
| 88 | 87 | connection: 'upgrade', | |
| Back | FazBrowse Home | New Git URL |
0 commit comments