Query Never Returned (Node.js Cassandra Driver)

332 views
Skip to first unread message

Yauri

unread,
Aug 31, 2015, 6:44:35 AM8/31/15
to DataStax Node.js Driver for Apache Cassandra Mailing List
I'm using Node.js Cassandra driver version 2.1.2
After several queries, some queries never return callback and disappear without any information, no error, no log at all.
Anyone here had similar issue?

There is one post that seems similar to my issue: https://groups.google.com/a/lists.datastax.com/d/msg/nodejs-driver-user/jnQZbBpYdVE/051lyyu_z6cJ

I didn't see any enqueing warning from the driver.
To solve this issue I have to restart my Node.js server to make the query back to normal.

I wonder if I misconfigured my Cassandra cluster or bug in Cassandra Node.js driver or my code problem.


Jorge Bay Gondra

unread,
Aug 31, 2015, 6:53:53 AM8/31/15
to nodejs-dr...@lists.datastax.com
Hi,
If you would like, you can share your code to see if we can help you find anything weird (ie: sync loop on async operations / incorrect error handling / ...) or out of place.

Jorge

To unsubscribe from this group and stop receiving emails from it, send an email to nodejs-driver-u...@lists.datastax.com.

Yauri

unread,
Aug 31, 2015, 7:02:15 AM8/31/15
to DataStax Node.js Driver for Apache Cassandra Mailing List
Here is my cassandra client
var Config = require('config');
var logger = require('./logger');
var Cassandra = require('cassandra-driver');

var cassandraClient = new Cassandra.Client(
    {
        'contactPoints': Config.get('Cassandra.host'),
        'socketOptions': { connectTimeOut: 5000 },
        'keyspace' : Config.get('Cassandra.keyspace')
    }
);

cassandraClient.on('log', function (level, className, message) {
    if (level != 'verbose') {
        logger.log(level, message);
    }
});

module.exports = cassandraClient;

Here is the simplest code of using cassandra client

var cassandraClient = require('../cassandra-client');
var Promise = require('bluebird');
var query = 'SELECT * FROM user WHERE user_id=?';

var getUser = function (userId) {
    return new Promise(function (resolve, reject) {
        cassandraClient.execute(query, [userId], {prepare: true}, function (err, result) {
            if (err) {
                reject(err);
            }
            resolve(result);
        });
    });
};

getUser('user1234')
    .then(function (res) {
        console.log(res); //never called
    })
    .catch(function (err) {
        console.error(err); //never called
    });




Jorge Bay Gondra

unread,
Aug 31, 2015, 7:17:04 AM8/31/15
to nodejs-dr...@lists.datastax.com
Hi,
I don't have much experience with BlueBird, but I think the promisification is not correctly made:
I think it should be:

if (err) {
  //exit the function
  return reject(err);
}
resolve(result);

I think you can automatically promisify the cassandra driver execute method by doing something like this: 

var execute = Promise.promisify(client.execute, client);
execute(query, params, { prepare: true })
  .then(...)
  .then(...);


I hope it helps,
Jorge

Yauri

unread,
Aug 31, 2015, 7:22:03 AM8/31/15
to nodejs-dr...@lists.datastax.com
Hi,

Sorry I missed that return on reject. Yes I have it in my code. I simply rewrite the codes because I left my notebook at the office.
I don’t think problem with that promisification but more like problem with how I configured my Cassandra cluster / connection problem.
Did you ever have similar issue?

Additional information: the query stuck after exception inside cassandra query callback.

-- 
Yauri
Sent with Airmail

Yauri

unread,
Aug 31, 2015, 7:33:50 AM8/31/15
to DataStax Node.js Driver for Apache Cassandra Mailing List

Jorge Bay Gondra

unread,
Aug 31, 2015, 7:37:40 AM8/31/15
to nodejs-dr...@lists.datastax.com
Those tickets are related to incorrect error handling from the users.

We did not have a similar issue. Furthermore, apart from integration tests available in our repository, we run automated duration and endurance tests (ie: with nodes failing) prior to each release, and we didn't experienced anything like that.

Let us know if you can not track the underlying case and you suspect that it can be caused by the driver.

To unsubscribe from this group and stop receiving emails from it, send an email to nodejs-driver-u...@lists.datastax.com.

Yau Ri

unread,
Aug 31, 2015, 7:57:34 AM8/31/15
to nodejs-dr...@lists.datastax.com

Ok, but in my opinion server uncaught exception should not affecting cassandra driver connection.

I am not sure if the exception happened outside the quey callback will cause same problem.

Yauri

unread,
Aug 31, 2015, 11:15:11 PM8/31/15
to DataStax Node.js Driver for Apache Cassandra Mailing List
Hi Jorge,

It seems like we hit the same problem like those closed cases. 

So here is my solution to for the problem:


var Promise = require('bluebird');
var cassandraClient = require('cassandraClient');

new Promise(function(resolve, reject)) {
cassandraClient.execute('SELECT * FROM user WHERE user_id=?', ['user-1'], {prepare:true}, function(err, result)) {
if(err) {
console.error(err);
reject(err);
                        return;
}
resolve(result);
});
})
.then(function(result)) {
//process logic + result here
//any error goes to catch below
})
.catch(function(err)) {
callback(err);
});

Thanks!
Reply all
Reply to author
Forward
0 new messages