Cannot connect to more than one bucket

As the headline suggests, I am unable to connect to more than one bucket.
The second openBucket fails with code 23: “Client-Side timeout exceeded for operation. Inspect network conditions or increase the timeout”.
The error occurs immediately after the openBucket call is made (so it’s not even waiting the 4 seconds timeout set in the cluster).
The first bucket is opened with no errors.

Thanks!

Couchbase version: 4.5.1-2844
NodeJs couchbase SDK version: 2.5.1
And here is the code that opens the buckets:

import * as couchbase from 'couchbase'
const logger = require('./loggerUtils')

var buckets = new Object();

let cluster = new couchbase.Cluster('couchbase://127.0.0.1:8091?operation_timeout=4');

export async function tryOpenBucket() {
  try {
    buckets['bucket1'] = await cluster.openBucket('bucket1', function (err) {
      if (err) {
        logger.error('tryOpenBucket openBucket 1 error', err)
        throw err
      }
    })
    buckets['bucket2'] = await cluster.openBucket('bucket2', function (err) {
      if (err) {
        logger.error('tryOpenBucket openBucket 2 error', err)
        throw err
      }
    })
    return Promise.resolve()
  } catch (err) {
    logger.error('tryOpenBucket openBucket error 2')
    return Promise.reject(err)
  }
}

Hey @gilad.teller,

Are you able to open the buckets in the opposite order? Typically, a timeout exception would be the result of an issue connecting to a specific bucket, as opposed to a particular ordering.

Cheers, Brett

1 Like

Hey @brett19,
Thanks for the reply!
After some more investigation, “throw err” was not caought in the try, and the entire app crashed.
Removing throw err, revealed that both openBucket calls failed with the same timeout error.
What I discovered was that a module called couchbase-connect that uses couchbase to handle express sessions was to blame.
It seems that I am getting the timeout error if I try to link the bucket to couchbase-connect and then start the express server.
This forced me to start using the bucket only after it is open.
Does this make sense? This is completely against all examples I found online that suggest to open the bucket and then start using it even if it is not open yet.

My current code:
getSessionStore is only called when openBucketSuccess event is fired.

import * as couchbase from 'couchbase'
const logger = require('./loggerUtils')
const config = require('../config')
const events = require('events').EventEmitter;
const e = new events();
var buckets = new Object()

let cluster = new couchbase.Cluster(`couchbase://127.0.0.1:8091?operation_timeout=4`);

export function getEvents(){
  return e;
}

export function tryOpenBucket(bucketName) {
  try {
    if (!buckets[bucketName]) {
      buckets[bucketName] = cluster.openBucket(bucketName, function (err) {
        if (err) {
          logger.error(`openBucket failed: ${bucketName}`, err)
          e.emit(`openBucketError_${bucketName}`)
        }
        else {
          e.emit(`openBucketSuccess_${bucketName}`)
        }
      })
    }
  } catch (err) {
    logger.error(`openBucket failed: ${bucketName}`, err)
    throw err
  }
}


export function getSessionStore(session, bucketName) {
  try {
    const CouchbaseStore = require('connect-couchbase')(session);
    const couchbaseStore = new CouchbaseStore({
      db: buckets[bucketName]
    });

    couchbaseStore.on('connect', function () {
      logger.info("Couchbase Session store is ready for use");
    });
    couchbaseStore.on('disconnect', function () {
      logger.error("An error occurred connecting to Couchbase Session Storage");
    });
    return couchbaseStore
  } catch (err) {
    logger.error(`getSessionStore: ${err}`)
    return null
  }
}

Hey @gilad.teller,

You’re right that it’s intended that you can immediately use a bucket without waiting for the connect event. I’ll have to take a look at what the couchbase-connect module is doing which is breaking our protection against performing operations before the bucket is connected.

Cheers, Brett