Uploaded image for project: 'Couchbase node.js Client Library'
  1. Couchbase node.js Client Library
  2. JSCBC-461

Truncated view errors cause crashes

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 2.4.6, 2.5.0-beta
    • 2.4.5
    • library
    • None
    • 1

    Description

      When a view error occurs, we try to parse the error that we get back from the view engine at https://github.com/couchbase/couchnode/blob/a3a240a2cf0d93e79a4051c33bce74094ca97cca/lib/bucket.js#L613.

      The problem is that the logic isn't quite complete here.

            var errStr = val;
            var jsonError = JSON.parse(errStr);
            var errorMessage = 'unknown error : error parsing failed';
            if (jsonError) {
              errorMessage = jsonError.message;
              if (jsonError.error || jsonError.reason) {
                var subError = jsonError.error + ': ' + jsonError.reason;
                if (!errorMessage) {
                  errorMessage = subError;
                } else {
                  errorMessage += ' (' + subError + ')';
                }
              }
            }
       
            var err = new Error(errorMessage);
            err.responseBody = errStr;
            emitter.emit('error', err);
      

      I think the overall logic is 'try to parse the json error, if that fails then just use the string', but we don't actually have any error handling around the json parsing.
      That means if you receive something that (for example) is truncated, the JSON.parse() will error out, but as we do not catch the error we never reach the rest of the logic.
      Even worse still it causes the application running the view query to crash.

      I am not sure exactly what causes invalid json to be passed through from the view engine, but given this occurs in a failure scenario, we should protect the SDK from crashes wherever possible.

      Attachments

        For Gerrit Dashboard: JSCBC-461
        # Subject Branch Project Status CR V

        Activity

          People

            brett19 Brett Lawson
            matt.carabine Matt Carabine (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty