marcelog / Nami

Asterisk manager interface (ami) client for nodejs
http://marcelog.github.com/Nami
Apache License 2.0
99 stars 59 forks source link

Trying to push to an undefined event. #16

Open human39 opened 10 years ago

human39 commented 10 years ago

Hello!

I built a call center monitoring application with NAMI.

I'm currently working on another program (not node.js/nami) to Originate a call. Every so often I'm getting the crash on the monitoring application

(Paths changed)

/home/user/app/node_modules/nami/src/nami.js:70 this.responses[event.actionid].events.push(event); ^ TypeError: Cannot read property 'events' of undefined at Nami.onRawEvent (/home/user/app/node_modules/nami/src/nami.js:70:39) at Nami.EventEmitter.emit (events.js:96:17) at Nami.onRawMessage (/home/user/app/node_modules/nami/src/nami.js:119:14) at Nami.EventEmitter.emit (events.js:96:17) at Nami.onData (/home/user/app/node_modules/nami/src/nami.js:142:14) at Socket.Nami.onWelcomeMessage (/home/user/app/node_modules/nami/src/nami.js:182:18) at Socket.EventEmitter.emit (events.js:96:17) at TCP.onread (net.js:392:31)

Even though I can't reproduce this all the time, I think this is directly related to my Originate or checking for OriginateResponse..

Other info: npm ls

├─┬ express@3.1.0 │ ├── buffer-crc32@0.1.1 │ ├── commander@0.6.1 │ ├─┬ connect@2.7.2 │ │ ├── bytes@0.1.0 │ │ ├── formidable@1.0.11 │ │ ├── pause@0.0.1 │ │ └── qs@0.5.1 │ ├── cookie@0.0.5 │ ├── cookie-signature@0.0.1 │ ├── debug@0.7.0 │ ├── fresh@0.1.0 │ ├── methods@0.0.1 │ ├── mkdirp@0.3.3 │ ├── range-parser@0.0.4 │ └─┬ send@0.1.0 │ └── mime@1.2.6 ├── http@0.0.0 ├─┬ jade@0.28.1 │ ├── coffee-script@1.4.0 │ ├── commander@0.6.1 │ └── mkdirp@0.3.4 ├─┬ nami@0.4.0 │ └── log4js@0.3.9 └─┬ socket.io@0.9.6 ├── policyfile@0.0.4 ├── redis@0.6.7 └─┬ socket.io-client@0.9.6 ├─┬ active-x-obfuscator@0.0.1 │ └── zeparser@0.0.5 ├── uglify-js@1.2.5 ├─┬ ws@0.4.20 │ ├── commander@0.6.1 │ ├── options@0.0.3 │ └── tinycolor@0.0.1 └── xmlhttprequest@1.2.2

rooftopsparrow commented 10 years ago

I am also seeing this randomly on boot. Trying to track down the source of the problem...I'll update here if I find the reason.

[2013-12-20T19:54:35.913Z] FATAL: liveserver/89541 on host: Cannot call method push of undefined
TypeError: Cannot call method push of undefined
    at Nami.onRawEvent (~/node_modules/nami/src/nami.js:77:47)
    at Nami.EventEmitter.emit (events.js:95:17)
    at Nami.onRawMessage (~/node_modules/nami/src/nami.js:130:14)
    at Nami.EventEmitter.emit (events.js:95:17)
    at Nami.onData (~/node_modules/nami/src/nami.js:153:14)
    at Socket.<anonymous> (~/node_modules/nami/src/nami.js:197:18)
    at Socket.EventEmitter.emit (events.js:95:17)
    at Socket.<anonymous> (_stream_readable.js:746:14)
    at Socket.EventEmitter.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:408:10)
rooftopsparrow commented 10 years ago

After dealing with this for a while I've narrowed it down to a quite specific case and is inline with the issue that @human39 is seeing as well.

When the socket is up and active, I can send an Action to AMI, like Ping for example, and get back Pong meaning that the keepalive was successful. However, there is a chance that the socket will get removed BEFORE response on the socket is fully read somehow.

Below is a scenario.

[2014-02-04T19:52:25.240Z]  INFO:  PING
[2014-02-04T19:52:25.561Z]  INFO:  PONG
[2014-02-04T19:52:25.561Z]  INFO:  Keep Alive successful
[2014-02-04T19:53:42.728Z]  INFO: PING
[2014-02-04T19:53:43.249Z]  WARN: Lost connection to the AMI. Reopening connection...
[2014-02-04T19:53:45.989Z] FATAL:  uncaughtException
    TypeError: Cannot call method push of undefined
        at Nami.onRawEvent (~/node_modules/nami/src/nami.js:77:47)
        at Nami.EventEmitter.emit (events.js:95:17)
        at Nami.onRawMessage (~/node_modules/nami/src/nami.js:130:14)
        at Nami.EventEmitter.emit (events.js:95:17)
        at Nami.onData (~/node_modules/nami/src/nami.js:153:14)
        at Socket.<anonymous> (~/node_modules/nami/src/nami.js:197:18)
        at Socket.EventEmitter.emit (events.js:95:17)
        at Socket.<anonymous> (_stream_readable.js:746:14)
        at Socket.EventEmitter.emit (events.js:92:17)
        at emitReadable_ (_stream_readable.js:408:10)
human39 commented 10 years ago

I've since updated NAMI and rewrote the other application that seemed to be triggering this bug in Node(using NAMI). I haven't been bitten by this since then. Unfortunately, I don't have any more useful information than that.

marcelog commented 10 years ago

hey guys, thanks for discussing this! is there any chance that i can get a small example that triggers this error? i'll be happy to work on this, just need more info, since i haven't run into this issue myself

rooftopsparrow commented 10 years ago

Hey @marcelog! Thanks for the interest.

Unfortunately its hard to reproduce because it is definitely based on network latency / stability. The network needs to be degraded to about 5-10% packet loss and some latency on the socket. If the network is really bad (really high packet loss and latency or even no connectivity), Nami performs as expected and cleanly kills the sockets. At least this is the experience I've had.

I will try to come up with a solid repro and let you know.

marcelog commented 10 years ago

hey :) mm interesting.. will look at the code, and see if i spot anything bad that could match with that scenario.. btw, sorry about not replying before (for both @rooftopsparrow and @human39), somehow i missed the email from github, please let me know if there are any updates, will do too

jbasg commented 10 years ago

Hola, ante todo felicitarte por el gran trabajo realizado. Yo he sufrido este error, creo que es debido a algún evento de respuesta a alguna accion hecha desde otra conexion ami . En mi caso lo he solucionado validando que exista el objeto this.responses[event.actionid] en el método onRawEvent


if (this.responses[event.actionid]){ this.responses[event.actionid].events.push(event) ; } Espero que sirva de ayuda. Saludos.

marcelog commented 9 years ago

Hey guys, could you join the comments on this pull https://github.com/marcelog/Nami/pull/30/files#r20016474? Seems to be the same thing or related, and more eyes could be useful :)