brikteknologier / seraph

A thin and familiar layer between node and neo4j's REST api.
MIT License
309 stars 59 forks source link

Having trouble closing db connection #211

Open StefanoDeVuono opened 7 years ago

StefanoDeVuono commented 7 years ago

When I run my test, the database connection stays open at the end, even if I ask to close it:

const wtf = require('wtfnode');

const test = require('tape'),
      db = require('seraph')({
        bolt: true,
        nodeify: true,
        pass: process.env.NEO4JPASSWORD
      });

test('nothing', t => {
  const person = { name: 'Jon', age: 22, likes: 'Beer', test: true };
  db.save(person, function(err, node) {
    let testNode = Object.assign({}, node);
    delete testNode.id;
    t.deepEqual(testNode, person);
    t.end();
  })
})

test.onFinish( () => {
  db.close();
  wtf.dump();
});

wtf shows an open socket, even though I've asked to close my db connection: 127.0.0.1:51255 -> 127.0.0.1:7687

I think this is due to the close method in seraph/bolt calling this.options.session && this.options.session.close();. Since there is no session object on the options key, the close method just returns undefined.

Raidus commented 6 years ago

I've did the same test with the official neo4j driver which leaves an open db connection, too.

const wtf = require('wtfnode');
const neo4j = require('neo4j-driver').v1;

// Config
const { NEO_URI, NEO_USER, NEO_PASS } = require('../config/keys');

// Neo4j
const driver = neo4j.driver(NEO_URI, neo4j.auth.basic(NEO_USER, NEO_PASS));
const session = driver.session();

const personName = 'Alice';
const resultPromise = session.run('CREATE (a:Person {name: $name}) RETURN a', {
  name: personName
});

resultPromise
  .then(result => {
    session.close();

    const singleRecord = result.records[0];
    const node = singleRecord.get(0);

    console.log(node.properties.name);

    // on application exit:
    driver.close();
  })
  .then(res => wtf.dump());