mladen
mladen

Reputation: 41

Couchbase 2.0 on node.js crashes when using multiple get

I am prototyping a project on a Mac OS X Mountain Lion 10.8.2 with Couchbase 2.0, node.js 0.8.19, couchbase module 0.0.11 and libcouchbase 2.0.3.

If the Couchbase bucket it empty (the two documents do not exist), the code below crashes the node process with the following. I built node with debug and used gdb to backtrace.

node_g(96149,0x7fff75619180) malloc: *** error for object 0x10300fb7f: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

Program received signal SIGABRT, Aborted.
0x00007fff8bbf7212 in __pthread_kill ()
(gdb) backtrace
#0  0x00007fff8bbf7212 in __pthread_kill ()
#1  0x00007fff8cd6eaf4 in pthread_kill ()
#2  0x00007fff8cdb2dce in abort ()
#3  0x00007fff8cd86959 in free ()
#4  0x0000000101e91c33 in lcb_server_purge_implicit_responses ()
#5  0x0000000101e89f09 in lcb_server_event_handler ()
#6  0x0000000101adebab in maybe_callout [inlined] () at :34
#7  0x0000000101adebab in async_cb (handle=<value temporarily unavailable, due to optimizations>, status=0) at ../io/common.c:68
#8  0x00000001000442ea in uv__async_io (loop=<value temporarily unavailable, due to optimizations>, handle=0x1c042a000000000, events=1060378680) at ../deps/uv/src/unix/async.c:117
#9  0x0000000100049c24 in ev_invoke_pending (loop=0x10082bd68) at ../deps/uv/src/unix/ev/ev.c:2145
#10 0x00000001000445e8 in uv__run (loop=0x10082b420) at ../deps/uv/src/unix/core.c:248
#11 0x0000000100044517 in uv_run (loop=0x10082b420) at ../deps/uv/src/unix/core.c:265
#12 0x0000000100008d9b in node::Start (argc=<value temporarily unavailable, due to optimizations>, argv=0x7fff5fbffb98) at ../src/node.cc:2974
#13 0x0000000100000cb4 in start ()

This works if the two documents already exist. It crashes only if the documents do not exist. If I don't use multi-get (but a view for example) to check if the docs exist - it works. If you ask why I explicitly check for existence and don't rely on CAS - most of the docs will already exist so I will anyway have to pull them before updating.

The same code works fine on (an Amazon-hosted) CentOS 6 image with the same versions of node.js and libraries.

Am I doing something wrong or there's a problem on Mac OS X? That is a simplified example to illustrate the problem. The full code merges the existing data with the new document and also does CAS checks, all of which is omitted here.

I couldn't find where to report bugs for Couchbase. JIRA is not open and the forum is kind of lame.

var async = require("async");
var couchBase = require("couchbase");

var json = {
  "id1": {
    "id": "id1",
    "name": "Name 1"
  },

  "id2": {
    "id": "id2",
    "name": "Name 2"
  }
};

var config = {
  "host": "localhost",
  "port": 8091,
  "username": "Administrator",
  "password": "password",
  "bucket": "requests"
};

couchBase.connect(config, function(err, bucket) {
  if (err) {
    console.log("Unable to connect to Couchbase bucket [" + config.bucket + "]", err);
    process.exit(1);
  }

  console.log("Connected to Couchbase");

  var ids = [];
  var jsonDocs = [];
  for (var key in json) {
    if (json.hasOwnProperty(key)) {
      var jsonDoc = json[key];
      var id = jsonDoc.id;

      jsonDocs.push(jsonDoc);
      ids.push(id);
    }
  }

  bucket.get(ids, null, function(err, docs, metas) {
    if (err) {
      for (var j = 0; j < err.length; j++) {
        if (err[j].code != 13) {
          console.log({ err: err }, "Unable to get existing entries using multiple get. Error in element [" + j + "]");
          process.exit(1);
        }
      }
    }
    console.log("Checked all docs for existance");

    async.map(jsonDocs, function(doc, callback) {
      bucket.set(doc.id, doc, {}, function(err) {
        callback(err);
      });
    }, function(err, results) {
      if (err) {
        console.log("Unable to save all entries", err);
        process.exit(1);
      }

      console.log("Saved all entries");
      process.exit(0);
    });
  });
});

Upvotes: 1

Views: 568

Answers (1)

Tug Grall
Tug Grall

Reputation: 3520

I have experienced the same issue on my application, and with your sample code. I will log a bug and put that in the list of fix for the next release of the SDK.

The JIRA is: http://www.couchbase.com/issues/browse/JSCBC-16

You could not log a bug?

I am also monitoring the forum, and just answered your question there too.

Upvotes: 1

Related Questions