Flotype / now

NowJS makes it easy to build real-time web apps using JavaScript
http://www.nowjs.com
MIT License
1.91k stars 175 forks source link

Now 0.7 - server dies on error #114

Closed AD7six closed 13 years ago

AD7six commented 13 years ago

The behavior between now 0.6 and now 0.7 is quite different if a call is made to a nonexistent method.

In the below console output the only relevant difference is the call to nowjs.doesntexist(); - simulating an attempt to call a now function defined on the client, which has been called on the server, before the client has sent the method definition.

Compare 0.6

[11:32][andy@work:~/projects/now/examples/multiroomchat_example(master)]$ git diff
diff --git a/examples/multiroomchat_example/multiroomchat_server.js b/examples/multiroomchat_example/multiroomchat_server.js
index efba1d5..c7e3dcd 100644
--- a/examples/multiroomchat_example/multiroomchat_server.js
+++ b/examples/multiroomchat_example/multiroomchat_server.js
@@ -1,15 +1,15 @@
 <U+FEFF>var fs = require('fs');
 var server = require('http').createServer(function(req, response){
   fs.readFile(__dirname+'/multiroomchat.html', function(err, data){
-    response.writeHead(200, {'Content-Type':'text/html'}); 
-    response.write(data);  
+    response.writeHead(200, {'Content-Type':'text/html'});
+    response.write(data);
     response.end();
   }); 
 }); 
 server.listen(8080);

-var nowjs = require("now");
+var nowjs = require("../../");
 var everyone = nowjs.initialize(server);

@@ -33,4 +33,5 @@ everyone.now.changeRoom = function(newRoom){

 everyone.now.distributeMessage = function(message){
   nowjs.getGroup(this.now.room).now.receiveMessage(this.now.name, message);
+  nowjs.doesntexist();
 };  
[11:33][andy@work:~/projects/now/examples/multiroomchat_example(master)]$ node multiroomchat_server.js 
4 Jul 11:33:09 - Your node instance does not have root privileges. This means that the flash XML policy file will be served inline instead of on port 843. This will slow down initial connections slightly.
4 Jul 11:33:09 - socket.io ready - accepting connections
4 Jul 11:33:13 - Initializing client with transport "websocket"
4 Jul 11:33:13 - Client 0018327960278838873 connected
Joined: andy
{ stack: [Getter/Setter],
  arguments: 
   [ 'doesntexist',
     { getGroup: [Function],
       getClient: [Function],
       initialize: [Function],
       generateClientLibs: [Function],
       socketio: [Object] } ],
  type: 'undefined_method',
  message: [Getter/Setter] }
TypeError: Object #<Object> has no method 'doesntexist'
    at Object.<anonymous> (/home/andy/projects/now/examples/multiroomchat_example/multiroomchat_server.js:36:9)
    at Object.<anonymous> (native)
    at Object.remoteCall (/home/andy/projects/now/lib/nowServerLib.js:90:19)
    at [object Object].<anonymous> (/home/andy/projects/now/lib/nowServerLib.js:288:46)
    at [object Object].emit (events.js:64:17)
    at [object Object]._onMessage (/home/andy/projects/now/node_modules/socket.io/lib/socket.io/client.js:58:10)
    at Parser.<anonymous> (native)
    at Parser.emit (events.js:64:17)
    at Parser.parse (/home/andy/projects/now/node_modules/socket.io/lib/socket.io/transports/websocket.js:195:12)
    at Parser.add (/home/andy/projects/now/node_modules/socket.io/lib/socket.io/transports/websocket.js:182:8)

(note the server instance is still running)

with 0.7

[11:36][andy@work:~/projects/now/examples/multiroomchat_example(0.7)]$ node multiroomchat_server.js 
   info  - socket.io started
   debug - served static /socket.io.js
   debug - client authorized
   info  - handshake authorized
   info  - handshaken b4fb0b342508455d49bfa257f71b1f22
   debug - setting request GET /socket.io/1/websocket/b4fb0b342508455d49bfa257f71b1f22
   debug - publishing that b4fb0b342508455d49bfa257f71b1f22 connected
   debug - initializing client store for b4fb0b342508455d49bfa257f71b1f22
   debug - set heartbeat interval for client b4fb0b342508455d49bfa257f71b1f22
   debug - subscribing b4fb0b342508455d49bfa257f71b1f22
   debug - websocket writing 1:: 
   debug - websocket writing 5:::{"name":"rv","args":[{"now.changeRoom":{"fqn":"now.changeRoom"},"now.distributeMessage":{"fqn":"now.distributeMessage"}}]}
   debug - websocket writing 5:::{"name":"rd"}
   debug - websocket received data packet 5:::{"name":"rv","args":[{"now.receiveMessage":{"fqn":"now.receiveMessage"},"now.name":"andy"}]}
   debug - got packet
   debug - websocket received data packet 5:::{"name":"rd"}
   debug - got packet
   debug - websocket received data packet 5:::{"name":"rfc","args":[{"fqn":"now.distributeMessage","args":["hello"]}]}
   debug - got packet

/home/andy/projects/now/examples/multiroomchat_example/multiroomchat_server.js:36
  nowjs.doesntexist();
        ^   
TypeError: Object [object Object] has no method 'doesntexist'
    at [object Object].<anonymous> (/home/andy/projects/now/examples/multiroomchat_example/multiroomchat_server.js:36:9)
    at [object Object].<anonymous> (native)
    at Socket.rfcHandler (/home/andy/projects/now/lib/user.js:25:19)
    at Socket.$emit (events.js:64:17)
    at SocketNamespace.handlePacket (/home/andy/projects/now/node_modules/socket.io/lib/namespace.js:238:20)
    at Manager.handlePacket (/home/andy/projects/now/node_modules/socket.io/lib/manager.js:538:34)
    at Memory.<anonymous> (/home/andy/projects/now/node_modules/socket.io/lib/manager.js:352:16)
    at Memory.emit (events.js:64:17)
    at Memory.publish (/home/andy/projects/now/node_modules/socket.io/lib/stores/memory.js:201:8)
    at Memory.message (/home/andy/projects/now/node_modules/socket.io/lib/stores/memory.js:132:15)
[11:36][andy@work:~/projects/now/examples/multiroomchat_example(0.7)]$ 

(note the server is dead)

steveWang commented 13 years ago

I'm going to hazard a guess and say that 0.6 doesn't crash because of the last three lines in nowServerLib of 0.6:

process.on('uncaughtException', function (err) {
  nowUtil.error(err);
});

Try 0fdd05cfe181ba127237d36ce93b743458686e1a?

AD7six commented 13 years ago

Try 0fdd05c?

When you tested @steveWang on 0fdd05c did it work?

steveWang commented 13 years ago

Yes, yes it did. Why, are you experiencing otherwise?

ericz commented 13 years ago

This should be fixed. Since 0fdd05c and also https://github.com/Flotype/now/commit/45a8c074251ab0ceca5a5a49bb49219bd82acd14