airbug / airbug-chat

Better chat for developers
Other
0 stars 0 forks source link

SonarBug. SonarBug server failure/files fail to write #71

Closed sungchoi closed 11 years ago

sungchoi commented 11 years ago

Under certain conditions Files fail to write due to logFilePath === undefined This causes the server to crash and restart Example:

    socket.on('tracklog', function(data){
            fs.appendFile(logFilePath, JSON.stringify(data) + '\n', function(){});
            console.log("tracklog:", "eventName:", data.eventName, "userID:", userID, "visitID:", visitID);
    });

Cause of error 1: Listeners were placed on global namespace socket manager instead of local ('socket-api') namespace manager. appendFile calls were not being executed.

Cause of error 2: Under the conditions of error 1, userID, visitID, logFileName, and logFilePath were not accessible to the local listener functions and came back undefined.

Cause of error 3: Unexpected behavior of class Queue (#dequeue method) See [airbug/airbug#70] Details: When userID, visitID, logFileName, and logFilePath were being set on 'startTracking', the backwards dequeueing would cause 'tracklog' and 'disconnect' events to be received before the 'startTracking' event. logFilePath would be undefined and error.

socketManager.of('namespace') returns a local namespace object with has its own socket as a property Fix: Move listeners to local namespace a.k.a. Manager object And move the userID and visitID generation to the serverside

        var ioManager           = io.listen(server); //Global namespace

        ioManager.set('match origin protocol', true); //NOTE: Only necessary for use with wss, WebSocket Secure protocol
        ioManager.set('resource', '/socket-api'); //NOTE: forward slash is required here unlike client setting
        ioManager
        .of('/socket-api') // local namespace manager
        .on('connection', function (socket) {
            console.log("Connection established")
            var userID = UuidGenerator.generateUuid();
            var visitID = UuidGenerator.generateUuid();
            var logFileName = userID + '-' + visitID + '.log';
            var logFilePath = activeFoldersPath + '/' + logFileName;

Secondary failsafe added: Example:

    socket.on('tracklog', function(data){
        if(logFilePath){
            fs.appendFile(logFilePath, JSON.stringify(data) + '\n', function(){});
            console.log("tracklog:", "eventName:", data.eventName, "userID:", userID, "visitID:", visitID);
        }  else {
            console.log('tracklog: Error: logFilePath is undefined');
       }
    });

Local Test Plan

Production Test Plan

Example log file: (file name should be [userID]-[visitID].log)

{"eventName":"connect","timestamp":"2013-04-17T01:46:18.793Z","data":null,"userID":"fbe8560b-e91e-6f99-8371-3530902dc2e7","visitID":"b222978e-3918-0948-8c34-c6ed64617c27"}
{"eventName":"appLoad","timestamp":"2013-04-17T01:46:18.793Z","data":null,"userID":"fbe8560b-e91e-6f99-8371-3530902dc2e7","visitID":"b222978e-3918-0948-8c34-c6ed64617c27"}
{"eventName":"pageView","timestamp":"2013-04-17T01:46:18.800Z","data":{"pageId":"explainerPage"},"userID":"fbe8560b-e91e-6f99-8371-3530902dc2e7","visitID":"b222978e-3918-0948-8c34-c6ed64617c27"}
{"eventName":"goalComplete","timestamp":"2013-04-17T01:46:26.710Z","data":{"goalName":"FeedbackSubmitted"},"userID":"fbe8560b-e91e-6f99-8371-3530902dc2e7","visitID":"b222978e-3918-0948-8c34-c6ed64617c27"}
{"eventName":"disconnect","userID":"fbe8560b-e91e-6f99-8371-3530902dc2e7","visitID":"b222978e-3918-0948-8c34-c6ed64617c27","timestamp":"2013-04-17T01:46:29.312Z","data":null}
sungchoi commented 11 years ago

@bneisler Ready for QA

brianneisler commented 11 years ago

QA looks good

brianneisler commented 11 years ago

released and closed