You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure if this project is under much active development, but I have a test program that reliably reproduces a case where the keep-alive-agent assigns a destroyed HTTPS socket to a request. The result is that the request never gets off the ground, and if this is the only thing that your Node program is doing, then Node just exits 0 because the event loop looks done.
The comments explain all this, but basically, the test program makes an HTTPS request, waits for a response, aborts the request, waits 50ms, and then makes another request. Every time I run it, the second request is assigned a socket that's already destroyed. As the program is written, it detects this and calls process.abort() to give you a core file. Here's what it looks like:
$ node katest.js
2015-07-03T00:32:05.328Z: creating request
2015-07-03T00:32:05.749Z: aborting after response received
2015-07-03T00:32:05.751Z: starting again in 50ms
2015-07-03T00:32:05.797Z: creating request
Error: assigned a destroyed socket!
at ClientRequest.<anonymous> (/home/dap/node-httpstream/tests/katest.js:111:8)
at ClientRequest.emit (events.js:117:20)
at http.js:1758:9
at process._tickCallback (node.js:419:13)
Abort (core dumped)
As written, it uses the keep-alive-agent Secure agent. You can change it to use the Node built-in agent, in which case the second request completes successfully:
$ node katest.js
2015-07-03T00:32:46.296Z: creating request
2015-07-03T00:32:46.704Z: aborting after response received
2015-07-03T00:32:46.705Z: starting again in 50ms
2015-07-03T00:32:46.751Z: creating request
2015-07-03T00:32:48.985Z: event: end (read 5242880 bytes)
$ echo $?
0
You can also see what happens if you take out the code that aborts when it detects a destroyed socket:
$ node katest.js
2015-07-03T00:33:29.510Z: creating request
2015-07-03T00:33:29.922Z: aborting after response received
2015-07-03T00:33:29.923Z: starting again in 50ms
2015-07-03T00:33:29.970Z: creating request
Error: assigned a destroyed socket!
at ClientRequest.<anonymous> (/home/dap/node-httpstream/tests/katest.js:111:8)
at ClientRequest.emit (events.js:117:20)
at http.js:1758:9
at process._tickCallback (node.js:419:13)
(not exiting on error)
$ echo $?
0
Note that it doesn't complete the second request, but just exits 0 (because the event loop has nothing to do).
The comment says that "TLS sockets null out their secure pair's ssl field", but at least on my version of Node (0.10.30), that doesn't always seem to be true.
In case it's helpful, the core file shows what the socket actually looks like (a lot of stuff snipped for brevity):
davepacacheo, is there any way to reuse a socket when using https. I am running a node soap server on https and using a meteor client along with keep-alive-agent using the Secure function but it does not reuse the sockets. I tried using the agent: new https.Agent() also but the sockets keep getting created newly for every method call i make from my client
import KeepAliveAgent from 'keep-alive-agent';
import https from 'https';
Meteor.startup(() => {
// code to run on server at startup
//var url = 'http://localhost/wsdl?wsdl';
var url = 'C:/meteorapps/soapclient/server/HelloService.wsdl';
var args = {firstName: 'Betty'};
//myAgent = new KeepAliveAgent.Secure( { maxSockets:1 } );
myAgent = new https.Agent();
var options = {
agent: myAgent,
headers: {"Connection":"Keep-Alive"},
maxSockets:1,
keepAlive:true,
keepAliveMsecs:3000,
}
try {
var client = Soap.createClient(url,options);
client.setSecurity(new Soap.ClientSSLSecurity(
'C:\\SSLkeyandcert\\server.key',
'C:\\SSLkeyandcert\\server.crt',
{
strictSSL:false,
},
));
client.addSoapHeader({Username:'Johnson'});
var result = client.sayHello(args,options);
console.log(result);
result = client.sayHelloHi({firstNameHi:'John'},options);
console.log(result);
}
catch (err) {
if(err.error === 'soap-creation') {
console.log('SOAP Client creation failed');
}
else if (err.error === 'soap-method') {
console.log(err);
}
}
});
I'm not sure if this project is under much active development, but I have a test program that reliably reproduces a case where the keep-alive-agent assigns a destroyed HTTPS socket to a request. The result is that the request never gets off the ground, and if this is the only thing that your Node program is doing, then Node just exits 0 because the event loop looks done.
Here's my test program:
https://gist.github.com/davepacheco/679eaf910b7e8df28406
The comments explain all this, but basically, the test program makes an HTTPS request, waits for a response, aborts the request, waits 50ms, and then makes another request. Every time I run it, the second request is assigned a socket that's already destroyed. As the program is written, it detects this and calls process.abort() to give you a core file. Here's what it looks like:
As written, it uses the keep-alive-agent Secure agent. You can change it to use the Node built-in agent, in which case the second request completes successfully:
You can also see what happens if you take out the code that aborts when it detects a destroyed socket:
Note that it doesn't complete the second request, but just exits 0 (because the event loop has nothing to do).
I believe the buggy code is in HTTPSKeepAliveAgent.isSocketUsable:
https://github.com/ceejbot/keep-alive-agent/blob/master/index.js#L121-L126
The comment says that "TLS sockets null out their secure pair's ssl field", but at least on my version of Node (0.10.30), that doesn't always seem to be true.
In case it's helpful, the core file shows what the socket actually looks like (a lot of stuff snipped for brevity):
The text was updated successfully, but these errors were encountered: