0

I have developed a realtime text web app using socket.io that continuously displays text on the web page. When I run my code below with multiple clients connecting the memory usage for the V8 javascript process on the server continues to grow and garbage collection doesn't appear to happen. Is it something with my code? Do I have a memory leak somewhere?

io.sockets.on('connection', function (socket) {
numOfUsers += 1;
var _RttPanes;

var sendText = function (input, callback) {
    var data = JSON.parse(input);
    socket.emit(data.action, input);
    callback();
};

socket.emit('RttConnect', 'connected');


socket.on('RttConnectRequest', function (strJsonMsg) {

    //add socket id to json string
    var intPosition = strJsonMsg.indexOf("}");
    var strFirstPart = strJsonMsg.substring(0, intPosition);

    var strNewJson = strFirstPart + ',"socketID":"' + socket.id + '"}';

    var payload = {
        jsonData: strNewJson,
        sendTranscriptToClient: sendText
    };

    //call ASP.NET code
    RttPaneConnect(payload, true);
    //RttPaneConnect(payload, function (error, result) {
    //    if (error) throw error;
    //    console.log(result);
    //});

    //Add property to the socket
    var message = JSON.parse(strNewJson);
    socket.UserName = message.username.toLowerCase();

});

socket.on('error', function (err) {

    console.log("socket.io-client 'error'", err);
    //reconnect();
});

socket.on('connect_failed', function () {

    console.log("socket.io-client 'connect_failed'");
    //reconnect();
});

socket.on('disconnect', function () {

    console.log("socket.io-client 'disconnect'");
    var strNewJson = '{"socketID":"' + socket.id + '"}';
    var payload = {
        jsonData: strNewJson,
        sendTranscriptToClient: sendText
    };
    //RttPaneDisconnect(payload, true);
    RttPaneDisconnect(payload, function (error) { console.log("socket.io-client 'disconnect EXIT'"); });

});

socket.on("LoggInUser", function (logInsocketid, logOffsocektid) {
    var clients = io.sockets.clients();
    for (i = 0; i < clients.length; i++) {
        if (clients[i].id == logInsocketid) {
            clients[i].emit("logOffCurrentUserSuccessful", logInsocketid, logOffsocektid);

            break;
        }
    }
});

socket.on('logOffCurrentUser', function (strJsonMsg) {

    var data = JSON.parse(strJsonMsg);
    var clients = io.sockets.clients();
    for(i=0;i<clients.length;i++){
        if (clients[i].UserName == data.username) {
            if(clients[i].id != socket.id){
                console.log("socket.io-client 'logOffCurrentUser' id: " + clients[i].id);

                var intPosition = strJsonMsg.indexOf("}");
                var strFirstPart = strJsonMsg.substring(0, intPosition);

                //add socket id to json string
                var strNewJson = strFirstPart + ',"socketID":"' + socket.id + '" , "clientSocketID":"' + clients[i].id + '"}';

                var payload = {
                    jsonData: strNewJson,
                    sendTranscriptToClient: sendText
                };

                //disconnect user from GLAS
                RttPaneDisconnectFirstAndConnectSecond(payload, function (error, result) {
                    if (error) {
                        console.log('Ahh! An Error!');
                        return;
                    }
                    console.log("forceLogOff socket.id, clients[i].id: " + socket.id + "   " + clients[i].id);
                    clients[i].emit("forceLogOff", socket.id, clients[i].id);
                });
                break;
            }
        }
    }
});
});

This is the edge.js code that calls my .net code to get the realtime text

var RttPaneDisconnect = edge.func({

references: ['System.Data.dll', 'bin\\Newtonsoft.Json.dll', 'bin\\LiveNoteStreamWeb.dll', 'bin\\StreamServerService.dll', 'System.Configuration.dll', 'System.Security.dll'],
source:
function () {/*

using System.Data;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Configuration;
using LiveNoteStreamWeb;
using StreamWeb;
using System.Security.Cryptography;
using System.Text;
using System;

public class Startup
{
    public WebRttPane _RttPane;
    public async Task<object> Invoke(dynamic data)
    {
    System.Diagnostics.Debugger.Break();
        WebRttPane _WebRttPane = new WebRttPane();
        _WebRttPane.StopRtt(data);
        return _WebRttPane;
    }
}

public class SessionInfo
{
    public string username, session, ew, token, socketID;
}

*/
}
});

var RttPaneConnect = edge.func({

    references: ['System.Data.dll', 'bin\\Newtonsoft.Json.dll', 'bin\\LiveNoteStreamWeb.dll', 'bin\\StreamServerService.dll', 'System.Configuration.dll', 'System.Security.dll'],
source:
function () {/*

using System.Data;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Configuration;
using LiveNoteStreamWeb;
using StreamWeb;
using System.Security.Cryptography;
using System.Text;
using System;

public class Startup
{
    public WebRttPane _RttPane;
    public async Task<object> Invoke(dynamic data)
    {
        //System.Diagnostics.Debugger.Break();
        WebRttPane _WebRttPane = new WebRttPane(data);
        _WebRttPane.StartRealTime();
       return _WebRttPane;       
    }
}

public class SessionInfo
{
    public string username, session, ew, token, socketID;
}

*/
}
});
ghort
  • 1
  • 1

0 Answers0