englercj / node-esl

FreeSWITCH ESL implementation for Node.js; implements the full Event Socket Library specified in: http://wiki.freeswitch.org/wiki/Esl
http://englercj.github.com/node-esl/
MIT License
170 stars 111 forks source link

JSON data not making it all the way through. #30

Closed clintberry closed 10 years ago

clintberry commented 10 years ago

Randomly, esl events won't make it all the way through. I see all the headers right up to the end, then the last part of the JSON data is cut off and no closing brace. So it errors on the JSON parse. The JSON data is pretty long, and I wonder if there is a size limit on the data that can come through the stream. Have you seen anything like this?

node v0.10.24

englercj commented 10 years ago

Interesting, I wonder if this is due to something strange like multi-byte characters making the Content-Length be off or something...

What version of the library are you using? Also, can you give me a copy-paste of the message that is being cut off so I can use it in a parser test and fix the issue (including all the headers as well). Something like changing parser.js#L27 to have a console.log:

Parser.prototype._onData = function(data) {
    console.log(data.toString(this.encoding));
    this.buffer = Buffer.concat([this.buffer, data], this.buffer.length + data.length);

    //if we have found a Content-Length header, parse as body
    if(this.bodyLen > 0)
        return this._parseBody();
    //otherwise this is more headers
    else
        return this._parseHeaders();
};
clintberry commented 10 years ago

So sorry, i was using an older version of node-esl. I didn't notice until after I posted the error. I've been watching events come through for an hour+ and no errors parsing. So whatever was updated seems to have fixed the issue for me.

Your library is awesome. Long live the JS powered telephone system! ;-)

englercj commented 10 years ago

Sweet! Someone had put in a PR for catching multi-byte characters that were offsetting the length so I thought that might have been it. Glad it is working for you now!