Skip to content

Crash if disconnected by the server while sending queued flood-protected messages #491

@Protected

Description

@Protected
TypeError: Cannot read property 'requestedDisconnect' of null
    at Client.send (.../node_modules/irc/lib/irc.js:936:19)
    at Timeout.dequeue (.../node_modules/irc/lib/irc.js:966:22)
    at Timeout.wrapper [as _onTimeout] (timers.js:425:11)
    at tryOnTimeout (timers.js:232:11)
    at Timer.listOnTimeout (timers.js:202:5)

It doesn't matter why it happens, I believe. This crash should occur if the connection is lost half way through for any reason.

Client.prototype.send = function(command) {
    var args = Array.prototype.slice.call(arguments);

    // Note that the command arg is included in the args array as the first element

    if (args[args.length - 1].match(/\s/) || args[args.length - 1].match(/^:/) || args[args.length - 1] === '') {
        args[args.length - 1] = ':' + args[args.length - 1];
    }

    if (this.opt.debug)
        util.log('SEND: ' + args.join(' '));

    if (!this.conn.requestedDisconnect) {  // ########## this.conn is null! ##########
        this.conn.write(args.join(' ') + '\r\n');
    }
};

It's probably enough to check if conn is set in the if?

if (this.conn && !this.conn.requestedDisconnect) {
    this.conn.write(args.join(' ') + '\r\n');
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions