martynsmith/node-irc — Issue #65: Race condition, mode+- before mode= seems to cause crash
Author: thejh
Created: 2011-11-15 22:19:13+00:00
State: open

> var irc=require('irc')
undefined
> var client = new irc.Client('irc.freenode.net', 'test378546', {channels:['#node.ks']})
undefined
>
/home/jann/tmp/node_modules/irc/lib/irc.js:511
throw err;
^
TypeError: Cannot call method 'indexOf' of undefined
at /home/jann/tmp/node_modules/irc/lib/irc.js:158:47
at Array.forEach (native)
at Client. (/home/jann/tmp/node_modules/irc/lib/irc.js:137:26)
at Client.emit (events.js:67:17)
at /home/jann/tmp/node_modules/irc/lib/irc.js:508:22
at Array.forEach (native)
at Socket. (/home/jann/tmp/node_modules/irc/lib/irc.js:505:15)
at Socket.emit (events.js:67:17)
at TCP.onread (net.js:322:31)

Wiresharks logs:

JOIN :#node.ks
:test378546!~nodebot@77-23-48-202-dynip.superkabel.de JOIN #node.ks
:sendak.freenode.net MODE #node.ks +ns
:sendak.freenode.net 353 test378546 @ #node.ks :@test378546
:sendak.freenode.net 366 test378546 #node.ks :End of /NAMES list.
[node crashed]

Code looks like the mode change handler expects the mode to be set, but node-irc requests the mode explicitely after joining so that automatic network-caused mode changes happen before the absolute mode is known. Just ignoring might cause node-irc to see a wrong channelmodes, so maybe it should just rerequest the absolute mode when such things happen? E.g. have a "relative changes happened" flag, set it to false on requesting absolute mode, set it to true when changes happen. When an absolute mode comes in and "relative changes happened" is true, rerequest.