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

get takes just under 2x timeout to report "collection not found"

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 3.0.0
    • 3.0.6
    • lcb, library
    • None
    • 1

    Description

      When a non-existent collection is specified. get() (and other) operations do not immediately return with "collection not found".  timeout is set to 3000 ms.  Get completes in 5959 ms with error (slightly less than 2x timeout) .  Subsequent get() calls with 5000ms timeout complete in around 9658 ms (output not shown, run kv-operations.js and hit localhost:3000/getwithoptions

      Also - I suspect the "UnhandledPromiseRejectionWarning" needs to be addressed based on "promise rejections that are not handled will terminate the Node.js process"

      % node kv2.js

      get: 5959

      ===========

      CollectionNotFoundError: collection not found

          at _getWrappedErr (/Users/michaelreiche/git/docs-sdk-nodejs/modules/howtos/examples/node_modules/couchbase/lib/errors.js:835:14)

          at Object.wrapLcbErr (/Users/michaelreiche/git/docs-sdk-nodejs/modules/howtos/examples/node_modules/couchbase/lib/errors.js:1008:20)

          at /Users/michaelreiche/git/docs-sdk-nodejs/modules/howtos/examples/node_modules/couchbase/lib/collection.js:218:24 {

        cause: LibcouchbaseError

      { code: 211 }

      ,

        context: KeyValueErrorContext {

          status_code: 4,

          opaque: 0,

          cas: CbCas

      { '0': <Buffer 00 00 00 00 00 00 00 00> }

      ,

          key: 'airport_77',

          bucket: 'travel-sample',

          collection: '',

          scope: '',

          context: '',

          ref: ''

        }

      }

      =========== get failed with 211

      ===========

      (node:4228) UnhandledPromiseRejectionWarning: Error: collection not found

          at _getWrappedErr (/Users/michaelreiche/git/docs-sdk-nodejs/modules/howtos/examples/node_modules/couchbase/lib/errors.js:835:14)

          at Object.wrapLcbErr (/Users/michaelreiche/git/docs-sdk-nodejs/modules/howtos/examples/node_modules/couchbase/lib/errors.js:1008:20)

          at /Users/michaelreiche/git/docs-sdk-nodejs/modules/howtos/examples/node_modules/couchbase/lib/collection.js:218:24

      (node:4228) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

      (node:4228) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

      ^C

      michaelreiche@hqml0612s-mbp examples %

       

      Attachments

        1. kv2.js
          1 kB
        2. kv-operations.js
          12 kB

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            sometimes only "timeout" is reported, and not the "collection not found".

             

            node kv-operations.js

            collection.constructor  bogus-collection

            get  timeout: 3000

            get  scope

            get  name bogus-collection

            get  key airport_77

            get: 10604

            ===========

            TimeoutError: timeout

                at _getWrappedErr (/Users/michaelreiche/git/docs-sdk-nodejs/modules/howtos/examples/node_modules/couchbase/lib/errors.js:815:14)

                at Object.wrapLcbErr (/Users/michaelreiche/git/docs-sdk-nodejs/modules/howtos/examples/node_modules/couchbase/lib/errors.js:1008:20)

                at /Users/michaelreiche/git/docs-sdk-nodejs/modules/howtos/examples/node_modules/couchbase/lib/collection.js:218:24 {

              cause: LibcouchbaseError

            { code: 201 }

            ,

              context: KeyValueErrorContext {

                status_code: 136,

                opaque: 0,

                cas: CbCas

            { '0': <Buffer 00 00 00 00 00 00 00 00> }

            ,

                key: 'airport_77',

                bucket: 'travel-sample',

                collection: '',

                scope: '',

                context: '',

                ref: ''

              }

            }

            =========== get failed with 201

            ===========

            michael.reiche Michael Reiche added a comment - sometimes only "timeout" is reported, and not the "collection not found".   node kv-operations.js collection.constructor  bogus-collection get  timeout: 3000 get  scope get  name bogus-collection get  key airport_77 get: 10604 =========== TimeoutError: timeout     at _getWrappedErr (/Users/michaelreiche/git/docs-sdk-nodejs/modules/howtos/examples/node_modules/couchbase/lib/errors.js:815:14)     at Object.wrapLcbErr (/Users/michaelreiche/git/docs-sdk-nodejs/modules/howtos/examples/node_modules/couchbase/lib/errors.js:1008:20)     at /Users/michaelreiche/git/docs-sdk-nodejs/modules/howtos/examples/node_modules/couchbase/lib/collection.js:218:24 {   cause: LibcouchbaseError { code: 201 } ,   context: KeyValueErrorContext {     status_code: 136,     opaque: 0,     cas: CbCas { '0': <Buffer 00 00 00 00 00 00 00 00> } ,     key: 'airport_77',     bucket: 'travel-sample',     collection: '',     scope: '',     context: '',     ref: ''   } } =========== get failed with 201 ===========

            I'm not familiar with nodejs/promise/reject processing, but to eliminate the UnhandledPromiseRejection, I believe it is sufficient to add a catch() to promisehelper.wrap - similar to asyncWrap.  callback has already been called with the err object by then.

            static async wrap(fn, callback) {
            return new Promise((resolve, reject) => {
            fn((err, res) => {
            if (err)

            { reject(err); }

            else

            { resolve(res); }

            if (callback)

            {   callback(err, res); }

            });
            }).catch((err)=>

            { console.log("CATCH : "+err); /* callback has already been called above */); }

            The callback can capture the exception, and it can be rethrown if the caller needs :

             

            async function getwithoptionsHandler(request, h) {
            var theErr;
            try {
            const result = await collection.get(docKey,

            { timeout: 5000, // 5 seconds }

            , (err, res) =>

            { if(err)  theErr = err; // to rethrow in caller if(res) console.log(res.value); }

            );

            if(theErr) // rethrow
            throw theErr;

            return h.response(result.value);
            } catch (e)

            { console.log(e); return h.response(e.toString()); }

            }

            michael.reiche Michael Reiche added a comment - I'm not familiar with nodejs/promise/reject processing, but to eliminate the UnhandledPromiseRejection, I believe it is sufficient to add a catch() to promisehelper.wrap - similar to asyncWrap.  callback has already been called with the err object by then. static async wrap(fn, callback) { return new Promise((resolve, reject) => { fn((err, res) => { if (err) { reject(err); } else { resolve(res); } if (callback) {   callback(err, res); } }); }).catch((err)=> { console.log("CATCH : "+err); /* callback has already been called above */); } The callback can capture the exception, and it can be rethrown if the caller needs :   async function getwithoptionsHandler(request, h) { var theErr; try { const result = await collection.get(docKey, { timeout: 5000, // 5 seconds } , (err, res) => { if(err)  theErr = err; // to rethrow in caller if(res) console.log(res.value); } ); if(theErr) // rethrow throw theErr; return h.response(result.value); } catch (e) { console.log(e); return h.response(e.toString()); } }

            The 'UnhandledPromiseRejection' can be resolved by chaining a 'catch' on to the collections.get() call :

            return collection.get(docKey, {timeout: 1000},
                        (err, res) =>

            {                 if(res) console.log(res);             }

            ).catch((e)=>{console.log(e); return h.response(e.toString()"<pre>"+e.stack"</pre>");});

            michael.reiche Michael Reiche added a comment - The 'UnhandledPromiseRejection' can be resolved by chaining a 'catch' on to the collections.get() call : return collection.get(docKey, {timeout: 1000},             (err, res) => {                 if(res) console.log(res);             } ).catch((e)=>{console.log(e); return h.response(e.toString() "<pre>"+e.stack "</pre>");});

            People

              brett19 Brett Lawson
              michael.reiche Michael Reiche
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty