jbmusso / gremlin-javascript

JavaScript tools for graph processing in Node.js and the browser inspired by the Apache TinkerPop API
MIT License
214 stars 63 forks source link

Error: this.connection.close is not a function #99

Open cyrilhamidechi opened 6 years ago

cyrilhamidechi commented 6 years ago

Execution environment AWS Lambda Node (node v6.3)

Code sample

'use strict';

const gremlin = require('gremlin');

exports.handler = (event, context, callback) => {
  const client = gremlin.createClient(8182, "gizmo", { accept: "application/vnd.gremlin-v2.0+json" });
  client.execute('g.V().limit(2)', (err, results) => {
    console.log(err, results);
    callback(null, 'Hello from Lambda');
  });
};

Description When running this code sample, lambda function never ends because connection is not closed. Then adding a client.closeConnection() throws the following error TypeError: this.connection.close is not a function at GremlinClient.closeConnection (/var/task/node_modules/gremlin/lib/GremlinClient.js:119:21)

Fix Adding directly client.connection.ws.close(); within the sample's callback makes the code sample work. In the same manner, at https://github.com/jbmusso/gremlin-javascript/blob/master/gremlin-client/src/GremlinClient.js#L83, replacing this.connection.close() by this.connection.ws.close() makes also the code sample work (but I don't know if it follows well current coding project pattern).

Bonus As a best practice, adding the close connection feature to documentation samples.