1

I’m using GridDB 5.7 with Node.js 16 on WSL2 Ubuntu 22.04. I can successfully connect to the GridDB node, but when I create a container and try to insert a row, I get a segmentation fault:

My code test.js:

const griddb = require('griddb-node-api');

async function main() {
    try {
        const factory = griddb.StoreFactory.getInstance();
        const store = factory.getStore({
            host: '127.0.0.1',
            port: 10001,
            clusterName: 'defaultCluster',
            username: 'admin',
            password: 'admin'
        });

        console.log('Connected to GridDB node!');

        const containerInfo = {
            name: 'sample_container',
            columnInfoList: [
                { name: 'id', type: griddb.Type.INTEGER },
                { name: 'name', type: griddb.Type.STRING }
            ],
            rowKey: true
        };

        let container = await store.putContainer(containerInfo);

        const row = [1, 'Ayman'];
        await container.put(row);

        console.log('Row inserted:', row);
    } catch (err) {
        console.error('Error:', err);
    }
}

main();

Output:

Connected to GridDB node!
Segmentation fault (core dumped)

What I have tried:

Verified the connection works.

Tried changing rowKey to 'id'.

Checked container schema matches the inserted row.

Ensured GridDB node is running and accessible.

What I to know: Why does this code cause a segmentation fault after connecting to GridDB? How can I safely insert a row without crashing Node.js?

Environment:

  • WSL2 Ubuntu 22.04
  • Node.js: 16.x
  • GridDB 5.7
  • griddb-node-api
1
  • Also nodejs is version 25.x on Linux Commented Nov 20 at 8:09

1 Answer 1

0

he crash isn’t really about your row values - it’s about how the GridDB Node API expects the container to be created.

With griddb-node-api you can’t pass an arbitrary plain object into putContainer.
The native addon expects an actual griddb.ContainerInfo instance, with columnInfoList in a very specific format and a container type set.

Right now you’re doing:

const containerInfo = {
    name: 'sample_container',
    columnInfoList: [
        { name: 'id', type: griddb.Type.INTEGER },
        { name: 'name', type: griddb.Type.STRING }
    ],
    rowKey: true
};

let container = await store.putContainer(containerInfo);
await container.put([1, 'Ayman']); // -> segfault

That object shape is not what GridDB’s Node API is written for, so the C++ code ends up dereferencing invalid data and segfaults.

From the official docs, the correct pattern is: docs.griddb.net+1

  • Use new griddb.ContainerInfo({ … })

  • columnInfoList is an array of 2-element arrays, not objects

  • You must specify type: griddb.ContainerType.COLLECTION (or TIME_SERIES)

  • putContainer usually takes a second argument (modifiable flag), e.g. false

Try this:

const griddb = require('griddb-node-api');

async function main() {
  try {
    const factory = griddb.StoreFactory.getInstance();
    const store = factory.getStore({
      // both styles are supported, but this one is from docs:
      notificationMember: '127.0.0.1:10001',
      clusterName: 'defaultCluster',
      username: 'admin',
      password: 'admin'
    });

    console.log('Connected to GridDB node!');

    const containerInfo = new griddb.ContainerInfo({
      name: 'sample_container',
      columnInfoList: [
        ['id',   griddb.Type.INTEGER],
        ['name', griddb.Type.STRING],
      ],
      type: griddb.ContainerType.COLLECTION,
      rowKey: true
    });

    // second arg: modifiable (false is fine for a simple example)
    const container = await store.putContainer(containerInfo, false);

    const row = [1, 'Ayman'];
    await container.put(row);
    await container.commit();  // good practice if autocommit is off

    console.log('Row inserted:', row);
  } catch (err) {
    console.error('Error:', err);
  }
}

main();
Sign up to request clarification or add additional context in comments.

1 Comment

Which version of node you used? As I was using node 16. By following your instructions, I haven't got expected result.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.