From 3da8267449619c52948b471ca9ebbade73aa73f0 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 10 May 2017 17:23:13 +0530 Subject: [PATCH] [temp] throttle socket io connection (#3260) --- socketio.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/socketio.js b/socketio.js index 16fb642a80..3b43fa7e04 100644 --- a/socketio.js +++ b/socketio.js @@ -7,6 +7,7 @@ var redis = require("redis"); var request = require('superagent'); var conf = get_conf(); +var flags = {}; var subscriber = redis.createClient(conf.redis_socketio || conf.redis_async_broker_port); // serve socketio @@ -31,6 +32,14 @@ io.on('connection', function(socket){ return; } + if(flags[sid]) { + // throttle this function + return; + } + + flags[sid] = sid; + setTimeout(function() { flags[sid] = null; }, 10000); + socket.user = cookie.parse(socket.request.headers.cookie).user_id; // console.log("firing get_user_info");