cloudant / nodejs-cloudant

Cloudant Node.js client library
Apache License 2.0
255 stars 90 forks source link

Error 500 when querying a view #383

Closed TatyanaBol closed 5 years ago

TatyanaBol commented 5 years ago

Bug Description

1. Steps to reproduce and the simplest code sample possible to demonstrate the issue

We have this code:

     db.view(designName, viewName, params, (err, body) => {
                if (err) {
                    logger.error(`Error calling view ${viewName}. Reason is: ${showError(err)}.`);
                    reject(buildError(err));
                } else {
                    resolve(body);
                }
            });

When we call this code FOR DIFFERENT VIEWS in our application SOMETIMES we get this error :

Error calling view certificates_all. Reason is: couch returned 500 - 500 - {gen_server,call,
    [couch_index_server,
     {get_index,
         {couch_mrview_index,
             {mrst,
                 <<172,96,3,183,238,234,89,252,215,239,156,46,159,23,54,57>>,
                 nil,undefined,
                 <<"shards/c0000000-cfffffff/1cf09ce6-ee17-4b83-9642-9974971a44c8-bluemix/certificates_store_dev.1551697028">>,
                 <<"_design/certificates_list_all">>,<<"javascript">>,[],
                 false,false,false,
                 {[]},
                 [{mrview,0,0,0,
                      [<<"certificates_all">>],
                      [],
                      <<"function(doc) {if (doc.type === 'certificate') {emit(doc.instance_id, doc._rev);}}">>,
                      nil,nil,nil,false,false,[]}],
                 nil,nil,0,0,undefined,undefined,undefined,undefined,
                 undefined,nil},
             <<"shards/c0000000-cfffffff/1cf09ce6-ee17-4b83-9642-9974971a44c8-bluemix/certificates_store_dev.1551697028">>,
             <<172,96,3,183,238,234,89,252,215,239,156,46,159,23,54,57>>}},
     infinity]} - {gen_server,call,
    [couch_index_server,
     {get_index,
         {couch_mrview_index,
             {mrst,
                 <<172,96,3,183,238,234,89,252,215,239,156,46,159,23,54,57>>,
                 nil,undefined,
                 <<"shards/c0000000-cfffffff/1cf09ce6-ee17-4b83-9642-9974971a44c8-bluemix/certificates_store_dev.1551697028">>,
                 <<"_design/certificates_list_all">>,<<"javascript">>,[],
                 false,false,false,
                 {[]},
                 [{mrview,0,0,0,
                      [<<"certificates_all">>],
                      [],
                      <<"function(doc) {if (doc.type === 'certificate') {emit(doc.instance_id, doc._rev);}}">>,
                      nil,nil,nil,false,false,[]}],
                 nil,nil,0,0,undefined,undefined,undefined,undefined,
                 undefined,nil},
             <<"shards/c0000000-cfffffff/1cf09ce6-ee17-4b83-9642-9974971a44c8-bluemix/certificates_store_dev.1551697028">>,
             <<172,96,3,183,238,234,89,252,215,239,156,46,159,23,54,57>>}},
     infinity]}.

In IBM Cloud Support Case CS0461614 it was recommended to retry request after this error. But in your documentation I found that retry logic works by default. It means that we got this error response after 3 re-tries. In last 2 days we have 51 hits of this error in our log (with re-tries it's 153 errors) What can be done to prevent this error?

2. What you expected to happen

View query returns results

3. What actually happened

View query returns error

Environment details

bessbd commented 5 years ago

Hi @TatyanaBol ,

Thank you for letting us know about this issue!

nodejs-cloudant's retry mechanism is only enabled if you have configured the retry plugin when you are initializing the client. See https://github.com/cloudant/nodejs-cloudant#plugin-configuration for further information. Can you please confirm that you have enabled the retry plugin? (As it is not enabled by default.)

Also, the 5xx error code clearly indicates this is a server-side issue. Whilst the retries may temporarily enable you to receive a response, it might be worth pursuing your support case a little further.

Donat

TatyanaBol commented 5 years ago

@bessbd Thank you for your answer. We didn't have retry plugin in our configuration. How to enable it with default values? Is this code correct?

cloudant = require('@cloudant/cloudant')({ url: dbUrl, 
        //maxAttempt: 3 by default, no need to set,
        plugins:  { retry: {} } //all default config parameters
    });

Thanks

ricellis commented 5 years ago
plugins: [ 'cookieauth', 'retry']

The default cookieauth plugin is only added if no other plugins are specified, so if you want to keep using that auth you'll need to specify it as well.

TatyanaBol commented 5 years ago

@ricellis Thanks! I'll try

bessbd commented 5 years ago

@TatyanaBol : it seems the nodejs-cloudant-related part of this issue is resolved. I'll close this issue. Please reopen or create another if there is anything else we can do for you.