This repository was archived by the owner on Apr 22, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
Access violation in nodejs when restarting a listening server #25365
Copy link
Copy link
Closed
Description
Nodejs version 0.12.3
Windows 7 and Windows 2012 x64
For our application we need a https or spdy server which can be restarted using a path on the filesystem. On the first call to open() this functions OK, however on the second call it often crashes nodejs. The crash occurs in
https://github.com/joyent/node/blob/master/src/stream_wrap.cc
on line 492. The variable wrap = NULL.
We have tried this with https as well as with spdy.
Code:
function RestartableHttps() {
var server = null;
var sockets = [];
var closing = false;
var setServer=function(options,hostName) {
server = spdy.createServer(options, app);
server.on('connection', function (socket) {
if (closing) {
socket.destroy();
return;
}
sockets.push(socket);
socket.once('close', function () {
console.log('socket closed');
sockets.splice(sockets.indexOf(socket), 1);
});
});
closing = false;
server.listen(443,hostName,function() {
console.log("Listening on 443");
});
}
var createCertOptions = function (path, type) {
var keyPath = path + '/Settings/' + type + '.key';
var certPath = path + '/Settings/' + type + '.crt';
var caCert = 'Webserver/ca.crt';
if (!fs.existsSync(keyPath))
return null;
if (!fs.existsSync(certPath))
return null;
if (!fs.existsSync(caCert))
return null;
var options = {
key: fs.readFileSync(keyPath),
cert: fs.readFileSync(certPath),
ca: [fs.readFileSync(caCert)]
};
return options;
}
var forcedClose = function (cb) {
if (server === null) {
cb();
return;
}
closing = true;
for (var i = 0; i < sockets.length; i++) {
sockets[i].destroy();
}
sockets = [];
server.close(cb);
}
this.open = function (path, certificateType,hostName) {
var open = function () {
var options = createCertOptions(path, certificateType);
if (options === null)
server = null;
else
setServer(options,hostName);
}
forcedClose(open);
}
}