3

On a cold start, my Lambda functions will return this error when trying to initialize a connection with Neptune. After that, the connection succeeds with no error. If the Lambda goes cold again the error returns.

    const dc = new DriverRemoteConnection(
      `wss://${process.env.NEPTUNE_ENDPOINT}:${process.env.NEPTUNE_PORT}/gremlin`,
      {}
    );
    const graph = new Graph();
    const g = graph.traversal().withRemote(dc);
    g.V();
    dc.close();

Using gremlin@^3.4.6 and Node 12.x. I found a similar error being reported against the ws package which was dismissed as an implementation error. https://github.com/websockets/ws/issues/1410

Do we need to somehow verify connections in advance when using Gremlin?

Edit: This problem seems to have started with gremlin@3.4.6. If I downgrade to gremlin@3.4.5 the problem goes away.

Edit 2: Got the error again with 3.4.5. 3.4.4 seems better.

Fook
  • 5,320
  • 7
  • 35
  • 57

2 Answers2

3

DriverRemoteConnection.close() is async operation, so you have to use await. Something like:

const dc = new DriverRemoteConnection(
  `wss://${process.env.NEPTUNE_ENDPOINT}:${process.env.NEPTUNE_PORT}/gremlin`,
  {}
);
const graph = new Graph();
const g = graph.traversal().withRemote(dc);
await g.V().limit(1).next();
await dc.close();

This helped me with the very same error

Ki Rill
  • 46
  • 4
0

You should use a terminal step and await on the promises to be resolve.

const gremlin = require('gremlin');
const { traversal } = gremlin.process.AnonymousTraversalSource;
const { DriverRemoteConnection } = gremlin.driver;

const rc = new DriverRemoteConnection(
  `wss://${process.env.NEPTUNE_ENDPOINT}:${process.env.NEPTUNE_PORT}/gremlin`)
const g = traversal().withRemote(rc);

async function run() {
  // await on Promise<Array>
  const result = await g.V().toList();
  console.log(result);
}

run();

Here you have some code samples on how to get started with the JavaScript Gremlin Variant: http://tinkerpop.apache.org/docs/current/reference/#gremlin-javascript

When working with AWS Lambda, you should not close the connection to the DB for each call, otherwise successive calls will fail.

jorgebg
  • 6,560
  • 1
  • 22
  • 31
  • Good catch but I have the same problem even with `await`. It works in 3.4.4 but not in 3.4.5. – Fook May 05 '20 at 14:39