0

I have the following node.js code running well, but I cannot seem to get console.log to execute - what could the reason be? The redis is in scope and the redis.get() works fine in an earlier location (so I know the syntax is fine).. The console.log that does not execute is commented with the line "# cannot execute this line" in the code. Would be grateful for any pointers on how to debug..

The program prints out 'pong' and 'pong2', so I know it is responding to a ping.

var WebSocketServer = require('ws').Server
var wss = new WebSocketServer({
    port: 8080
});
var redis = redis_server.createClient(6379, 'localhost');

wss.on('connection', function(ws) {
    ws_auth(redis, ws, function(authresult, uid) {
        if (!authresult) {
            ws.close();
            return;
        }
        ws.on('ping', function() {
            console.log('pong')
            var cookie = ws.upgradeReq.headers.cookie;
            cookie_json = JSON.parse(cookie);
            redis.get('session:' + cookie_json.sessionid, function(err, value) {
                console.log(getDateTime() + ': value ' + value + " session exits");#cannot execute this line
            });
            ws.pong();
            console.log('pong2')
        });
    });
});
Trewq
  • 3,187
  • 6
  • 32
  • 50
  • Is some client sending a `ping` message to your server to trigger that first `console.log()` statement? You may want to read this: http://stackoverflow.com/a/10586583/816620. – jfriend00 Apr 11 '15 at 02:12
  • @jfriend00 Thanks - The program prints out 'pong', so I know it is responding to a ping. – Trewq Apr 11 '15 at 02:15
  • then perhaps you should clarify in your question which `console.log()` you're asking about. – jfriend00 Apr 11 '15 at 02:16
  • @jfriend00 I did - the code says "# cannot execute this line" - but I will add this to the question body rather than the code. – Trewq Apr 11 '15 at 02:20
  • What is `ws_auth()`? It's being passed the `redis` handle, so it may be doing stuff to it that is causing `redis.get()` to fail somehow. – robertklep Apr 11 '15 at 06:50
  • Add try catch block around the code to see what exception is being thrown. May be that can give you some pointers. – andHapp Apr 11 '15 at 17:52

1 Answers1

0

Perhaps the JSON.parse is throwing an error which is being swallowed. It would be valuable to determine if the reddit server is receiving an event or not.

Venar303
  • 313
  • 3
  • 6
  • Thank for the reply! I updated the code to reflect that is prints pong and pong2 (shows that it is going through the code). cookie_json.sessionid also evaluated properly (I replaced the whole key with 'name' and no difference. I also ran redis in monitor mode, and I see that that the string gets set in redis, but the command from the .js program never reaches the redis server. – Trewq Apr 11 '15 at 02:29