Skip to content

Commit 4b70b26

Browse files
authored
Merge pull request #1057 from chrisradek/default/maxSockets
Sets a default value for maxSockets of 50 when the https.globalAgent.maxSockets is set to Infinity.
2 parents 4fdaa97 + ea548f2 commit 4b70b26

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/http/node.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,13 @@ AWS.NodeHttpClient = AWS.util.inherit({
114114
AWS.NodeHttpClient.sslAgent = new https.Agent({rejectUnauthorized: true});
115115
AWS.NodeHttpClient.sslAgent.setMaxListeners(0);
116116

117-
// delegate maxSockets to globalAgent
117+
// delegate maxSockets to globalAgent, set a default limit of 50 if current value is Infinity.
118+
// Users can bypass this default by supplying their own Agent as part of SDK configuration.
118119
Object.defineProperty(AWS.NodeHttpClient.sslAgent, 'maxSockets', {
119120
enumerable: true,
120-
get: function() { return https.globalAgent.maxSockets; }
121+
get: function() {
122+
return https.globalAgent.maxSockets !== Infinity ? https.globalAgent.maxSockets : 50;
123+
}
121124
});
122125
}
123126
return AWS.NodeHttpClient.sslAgent;

test/node_http_client.spec.coffee

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@ if AWS.util.isNode()
99
it 'delegates maxSockets from agent to globalAgent', ->
1010
https = require('https')
1111
agent = http.sslAgent()
12+
https.globalAgent.maxSockets = 5
1213
expect(https.globalAgent.maxSockets).to.equal(agent.maxSockets)
1314
https.globalAgent.maxSockets += 1
1415
expect(https.globalAgent.maxSockets).to.equal(agent.maxSockets)
1516

17+
it 'overrides globalAgent value if global is set to Infinity', ->
18+
https = require('https')
19+
agent = http.sslAgent()
20+
https.globalAgent.maxSockets = Infinity
21+
expect(agent.maxSockets).to.equal(50)
22+
1623
describe 'handleRequest', ->
1724
it 'emits error event', (done) ->
1825
req = new AWS.HttpRequest 'http://invalid'

0 commit comments

Comments
 (0)