SDK 3.0.7 - Segmentation fault calling viewQuery


Ubuntu 18.04
SDK 3.0.7
Couchbase 6.6.0 Community edition

I am getting a segmentation fault when passing a “keys” array of a certain size to bucket.viewQuery().
When I say a certain size, this seems to be the bytesize of the keys array, not the number of keys.
I have created a very simple view. The definition of this view isn’t actually important,nor is the data in the bucket. The view just emits

If I call this key with a keys array containing 77 values totalling around 2590 bytes, I get a segmentation fault. If I decrease this size slightly by either reducing the number or length of the keys, it works. If I increase the size by increasing either the number or length of keys it doesn’t crash but I get err LCB_ERR_VALUE_TOO_LARGE. There’s just this sweet spot in the middle that causes a seg fault.

In this test, none of the keys actually exist in the bucket (they’re just random strings I create for this test) but I don’t think that should matter.

I get this crash on all SDK version s from 3.0.0 to the latest (3.0.7). I have also tried Couchbase 6.0.0 and 6.6.0.
Before upgrading to 3.0.7 I was using 2.6 and I could do a view for any number of keys with no problem (I used to request 250 at a time and didn’t see a VALUE_TOO_LARGE error).

Please see the code below, that I am using to produce this error. You may need to modify NUM or KEYSIZE to cause a crash.

var couchbase = require('couchbase');
const SegfaultHandler = require('segfault-handler');

// Main processing.
(function() {
  function bytesize(arr) {
    return arr.reduce((total, arr) => total + (arr.length * 2), 0);

  const cluster = new couchbase.Cluster("couchbase://localhost", {
    username: "Administrator",
    password: "password"
  const bucket = cluster.bucket("mybucket");

  const NUM = 77;
  const KEYSIZE = 10;
  const keys = [];
  for (var i = 0; i < NUM; i++) {

  console.log(`Keys array: ${NUM} keys, size ${bytesize(keys)} bytes`);

  return bucket.viewQuery("giles", "test", { keys }).then(results => {
    console.log("viewQuery results", results);

  }).catch(err => {
    console.log("*** ERR", err);

This code uses segfault-handler to output a stack. This is the output:

Segmentation fault (core dumped)


@ericb , @brett19 can you please assist

Hi @AV25242 ,

Has anyone had a chance to look into this?


Hello @giles there was a fix for Segmentation fault in 3.1 that was released yesterday and a similar forum post discusses about it. Can you see if this helps

1 Like

Hi @AV25242, thanks for the reply. I have tested 3.1.0 and I no longer see this seg fault.


1 Like

@giles sorry for the delay and glad that it helped :slight_smile: :slight_smile:

1 Like