Skip to content

Commit

Permalink
fixed race condition and scoping bug
Browse files Browse the repository at this point in the history
  • Loading branch information
einaros committed Oct 25, 2011
1 parent 8253ed5 commit 357a9cb
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/transports/flashsocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ FlashSocket.prototype.name = 'flashsocket';
* @api private
*/

var server;

FlashSocket.init = function (manager) {
var server;
function create () {
server = require('policyfile').createServer({
log: function(msg){
Expand Down Expand Up @@ -80,13 +80,15 @@ FlashSocket.init = function (manager) {
// destory the server and create a new server
manager.on('set:flash policy port', function (value, key) {
var transports = manager.get('transports');

if (server && server.port !== value && ~transports.indexOf('flashsocket')) {
// destroy the server and rebuild it on a new port
try {
server.close();
if (~transports.indexOf('flashsocket')) {
if (server) {
if (server.port === value) return;
// destroy the server and rebuild it on a new port
try {
server.close();
}
catch (e) { /* ignore exception. could e.g. be that the server isn't started yet */ }
}
catch (e) { /* ignore exception. could e.g. be that the server isn't started yet */ }
create();
}
});
Expand All @@ -97,7 +99,6 @@ FlashSocket.init = function (manager) {
create();
}
});

// check if we need to initialize at start
if (~manager.get('transports').indexOf('flashsocket')){
create();
Expand Down

0 comments on commit 357a9cb

Please sign in to comment.