drachtio-srf icon indicating copy to clipboard operation
drachtio-srf copied to clipboard

Strange occational exception

Open jonastelzio opened this issue 3 years ago • 7 comments

Hi there,

So, I'm getting these exceptions occasionally, but I'm not quite sure what it's about:

TypeError: Cannot read property 'length' of undefined
    at parseMultiHeader (/app/node_modules/drachtio-srf/node_modules/drachtio-sip/lib/parser.js:85:22)
    at contact (/app/node_modules/drachtio-srf/node_modules/drachtio-sip/lib/parser.js:161:14)
    at SipMessage.getParsedHeader (/app/node_modules/drachtio-srf/node_modules/drachtio-sip/lib/message.js:91:12)
    at new Dialog (/app/node_modules/drachtio-srf/lib/dialog.js:71:39)
    at /app/node_modules/drachtio-srf/lib/srf.js:284:24
    at DrachtioAgent.<anonymous> (/app/node_modules/drachtio-srf/lib/drachtio-agent.js:346:11)
    at DrachtioAgent._onMsg (/app/node_modules/drachtio-srf/lib/drachtio-agent.js:727:11)
    at WireProtocol.emit (node:events:369:20)
    at WireProtocol.emit (node:domain:470:12)
    at WireProtocol.processMessageBuffer (/app/node_modules/drachtio-srf/lib/wire-protocol.js:270:12)

It's being caught by this code:

process.on('uncaughtException', (err) => {
    console.error("uncaught exception", err);
});

What I can see, else where in my code, is that req.receivedOn is undefined, but I'm not sure how that's possible. I'm running in Outbound mode, which could be relevant I reckon(?).

I've tried correlating these logs with drachtio-servers, but I've found nothing particularly interesting, and I can't explicitly find out what causes this, so I'm not effectively able to just enable full debugging on SRF in hopes to find out what's going on.

We're getting these in production, and they do seem harmless, but still, they're errors.

jonastelzio avatar Oct 20 '21 10:10 jonastelzio

It looks like an issue parsing an incoming Contact header. Would you be able to correlate it with the incoming SIP request?

davehorton avatar Oct 20 '21 12:10 davehorton

@davehorton is it possible to somehow get a hold of the SIP Message it failed to parse as part of the error?

jonastelzio avatar Oct 20 '21 18:10 jonastelzio

Its' tough....I would think this would be a incoming message that we did not respond to, probably a register

davehorton avatar Oct 20 '21 18:10 davehorton

I've added this now:

//Drachtio server ip middleware
srf.use((req, res, next) => {
    try {
        let drachtioServerIp = req.receivedOn;
        const colonLocation = drachtioServerIp.indexOf(':');
        if (colonLocation > 0) {
            drachtioServerIp = drachtioServerIp.substring(0, colonLocation);
        }
    
        req.telzioContext.drachtioServerIp = drachtioServerIp;
        debug(`SRF ${req.method} Request from ${drachtioServerIp}`);
    }
    catch (e) {
        req.telzioContext.logger.error("Exception in drachtio server ip middleware", e, {sip_raw: req.msg.raw});
        throw e;
    }

    next();
});

That'll at least get me the SIP Message logged next time it happens

jonastelzio avatar Oct 21 '21 13:10 jonastelzio

I've not seen this exception in quite a while. Perhaps it went away when upgrading to a more recent version of the drachtio-srf package!

jonastelzio avatar Nov 03 '21 12:11 jonastelzio

@davehorton

I've gotten this error again, and it turns out it's a BYE request with both a to/from tag - so not a dialog forming request.

Any idea what would cause something like that to end up in middleware like that?

jonastelzio avatar Nov 11 '21 10:11 jonastelzio

not sure...can you send the piece of the drachtio log showing the BYE?

davehorton avatar Nov 11 '21 12:11 davehorton