Couchbase client fail to connect server

I try to run application locally connect to the Couchbase in the datacenter via ssh tunneling.

here is my tunnel config

ssh config

Host cma.couchbase.prod
  User svccma
  IdentityFile ~/.ssh/some.key
  IdentitiesOnly yes
  StrictHostKeyChecking no
  Hostname some-machine.abc.org
  LocalForward 8091 172.30.123.47:8091
  LocalForward 8092 172.30.123.47:8092
  LocalForward 8093 172.30.123.47:8093
  LocalForward 8094 172.30.123.47:8094
  LocalForward 8095 172.30.123.47:8095
  LocalForward 8096 172.30.123.47:8096
  LocalForward 8097 172.30.123.47:8097
  LocalForward 9140 172.30.123.47:9140
  LocalForward 11210 172.30.123.47:11210
  ProxyCommand ssh ssm-bastion -W %h:%p

after tunnel this I can access Couchbase console via 127.0.0.1:8091 or call a query restful service successful via 127.0.0.1:8093 However, for some reason I cannot connect Couchbase with NodeJS SDK

Error

Query failed:  [Error: LCB_ERR_NETWORK (1048): Generic network failure] {
  code: 1048,
  ctxtype: 'query',
  first_error_code: 0,
  first_error_message: '',
  statement: '\n' +
    '        SELECT orderRef, countryCode, storeNumber, status\n' +
    '        FROM `Checkout` \n' +
    '        WHERE `_class` = "com.abc.checkout.entity.CheckoutEntity" \n' +
  parameters: '',
  http_response_code: 0,
  http_response_body: ''
}

COUCHBASE_HOST = 127.0.0.1

async function main() {
    console.log('Connecting to...' + process.env.COUCHBASE_HOST)
    const cluster = await couchbase.connect('couchbase://' + process.env.COUCHBASE_HOST, {
        username: process.env.COUCHBASE_USERNAME,
        password: process.env.COUCHBASE_PASSWORD,
    })

    // get a reference to our bucket
    const bucket = cluster.bucket(process.env.COUCHBASE_BUCKET_NAME);
    const collection_default = bucket.defaultCollection();
    console.log('Fetching data...' + process.env.COUCHBASE_HOST)
    const query = `
        SELECT orderRef, countryCode, storeNumber, status
        FROM \`Checkout\` 
        WHERE \`_class\` = "com.abc.checkout.entity.CheckoutEntity" 
        AND \`status\` NOT IN  ['SUCCESS', 'CANCELLED']
        AND DATE_DIFF_STR(NOW_LOCAL(), MILLIS_TO_LOCAL(lastModifiedDate), 'minute') > $1
        AND DATE_DIFF_STR(NOW_LOCAL(), MILLIS_TO_LOCAL(lastModifiedDate), 'hour') < $2
    `;
    const options = { parameters: [5, 48] }

    try {
        let result = await cluster.query(query, options)
        if (result.rows.length > 0) {

          // do something next.......

        }
        else {
            console.log('There are no in-processing checkouts....');
        }

    } catch (error) {
        console.error('Query failed: ', error)
    }

}

There are 8 nodes in total (2 query node)

  • 172.30.123.47 (Query)
  • 172.30.123.48 (Query)

Any idea???

Us sdk doctor to diagnose connectivity issues.

Hi @sattha,

I try to run application locally connect to the Couchbase in the datacenter via ssh tunneling.

If you need an SSH tunnel to access the Couchbase cluster, you’ll probably need to configure each Couchbase Server node to advertise the corresponding SSH tunnel address as an alternate address. Your tunnel will need port mappings for each node in the Couchbase cluster.

After the client connects to one node of the cluster, it asks the node for the addresses of all nodes in the cluster. The client then discards the node info from the connection string, and uses the addresses from the server to connect to all the nodes. So… each Couchbase Server node must be able to tell the client how to connect to it through the SSH tunnel. That’s what alternate addresses are for.

Thanks,
David

1 Like