Bug report for node couchbase

#1

@brett19 this is a new issue introduced in couchbase 2.1.7. On running many n1ql queries you get the stack trace below.

In the future, if couchbase on github enables issues, I’d file this there.

/Users/mda/sw/ow-back/node_modules/couchbase/lib/n1qlquery.js:82
    throw new Error('consistency and consistentWith must be use exclusively.');
    ^

Error: consistency and consistentWith must be use exclusively.
    at N1qlStringQuery.consistency (/Users/mda/sw/ow-back/node_modules/couchbase/lib/n1qlquery.js:82:11)
    at Models.runN1ql (/Users/mda/sw/ow-back/dist/models/index.js:346:12)
    at /Users/mda/sw/ow-back/dist/models/index.js:234:13
    at handler (/Users/mda/sw/ow-back/node_modules/ottoman/lib/ottoman.js:901:9)
    at /Users/mda/sw/ow-back/node_modules/ottoman/lib/cbstoreadapter.js:508:7
    at /Users/mda/sw/ow-back/node_modules/ottoman/lib/cbstoreadapter.js:443:32
    at N1qlQueryResponse.<anonymous> (/Users/mda/sw/ow-back/node_modules/couchbase/lib/bucket.js:733:7)
    at emitTwo (events.js:100:13)
    at N1qlQueryResponse.emit (events.js:185:7)
    at /Users/mda/sw/ow-back/node_modules/couchbase/lib/bucket.js:667:17

The problem I tracked down to this bit of this commit:

Here, a consistentWith function is introduced that can’t be used in combination with consistency. It seems if some other code does N1qlQuery.fromString and then adjusts the consistency with consistency this results, although I can’t trace where/how consistentWith is getting called to create the conflict.

Here’s the code of the function (runN1ql) that’s provoking the error:

  /**
   * Returns a promise to run the given n1ql query against the db.
   * @param query either a couchbase.N1qlQuery (pre-prepared) or a stringify
   * @param parameterBindings if any
   * @returns a promise that resolves to query results.
   */
  runN1ql(query, parameterBindings = {}, options = {}) {
    let n1ql = query;

    if (!(query instanceof couchbase.N1qlQuery)) {
      n1ql = couchbase.N1qlQuery.fromString(query);
    }

    // log.info('Executing n1ql query', { n1ql });

    n1ql.consistency(options.consistency || DEFAULT_N1QL_CONSISTENCY);

    return new Promise((resolve, reject) => {
      this.bucket.query(n1ql, parameterBindings, (err, rows, meta) => {
        if (err) { return reject(err); }
        return resolve({ rows, meta });
      });
    });
  }
#2

Hey @moxious!
Good catch. This is definitely a bug, and it from what I can tell it does not related to your use of consistentWith. I have created an issue for this here: https://issues.couchbase.com/browse/JSCBC-305, and a fix should be available shortly which will show up in our next client release.
Cheers, Brett

#3

Hey @moxious,
The bug fix is now available on our canonical repository available here:


Cheers, Brett

#4

Any chance we can get a new version published with this fix? This broke some of our code as well. :[

#5

Hey @evanlucas,
There should be a release later this evening if my build servers start cooperating.
Cheers, Brett

1 Like
#6

As of right now, couchbase 2.1.8 is available; can report it fixes the issue I’m reporting above (at least for me. :slight_smile: