Skip to content

Session and driver not closing; can still post queries @1.7.2 #442

Closed
@greekdude90

Description

@greekdude90

After closing my session and driver, I am still able to connect using the same session. I created the below log4js appender to log directly to neo4j.

`const neo4j = require('neo4j-driver').v1;
const driver = neo4j.driver('bolt://example.com:7687', neo4j.auth.basic('neo4j', 'test'));
const session = driver.session();

var createStmt;
function neo4jAppender( layout, timezoneOffset ){
return function(loggingEvent){
loggingEvent.data.forEach( (entry, idx) => {
createStmt = CREATE( log:Log:${entry.action};

                    var props = [];
                    Object.keys( entry.properties ).map( (k,i) => {
                            props.push( `${k}: $${k}` );
                    });

                    if( props.length > 0 ){
                            createStmt += ' {' + props.join() + '})'
                    }else{
                            createStmt += ') RETURN log'
                    }

                    const resultPromise = session.run( createStmt, entry.properties );

                    resultPromise.then( result => {
                            console.log( session );
                            session.close( () => {console.log('closed session' )});
                            console.log( session );

                            driver.close();
                    }).catch( (err) => {
                            console.log( err );
                    });
            });
    };

}

function configure( config, layouts ){
return neo4jAppender( null, config.timezoneOffset);
}

exports.configure = configure;`

Neo4j Version: 3.5.0 Community
Neo4j Mode: Single instance
Driver version: JS driver 1.7.2
Operating System: Ubuntu 18.04.1 LTS Docker (Docker version 1.13.1) (nodejs and neo4j are in their own containers)

Steps to reproduce

  1. Start Neo4j in docker
  2. Run a query with the driver
  3. Run another query

Expected behavior

The second query should error out

Actual behavior

The second query is successfully posted. I print out the session object before and after I call to close the session.
First session output:

Session { _mode: 'WRITE', _readConnectionHolder: ConnectionHolder { _mode: 'READ', _connectionProvider: DirectConnectionProvider { _hostPort: 'example.com:7687', _connectionPool: [Pool], _driverOnErrorCallback: [Function: bound _driverOnErrorCallback] }, _referenceCount: 0, _connectionPromise: Promise { null, domain: [Domain] } }, _writeConnectionHolder: ConnectionHolder { _mode: 'WRITE', _connectionProvider: DirectConnectionProvider { _hostPort: 'example.com:7687', _connectionPool: [Pool], _driverOnErrorCallback: [Function: bound _driverOnErrorCallback] }, _referenceCount: 0, _connectionPromise: Promise { undefined, domain: [Domain] } }, _open: true, _hasTx: false, _lastBookmark: Bookmark { _values: [ 'neo4j:bookmark:v1:tx34' ], _maxValue: 'neo4j:bookmark:v1:tx34' }, _transactionExecutor: TransactionExecutor { _maxRetryTimeMs: 30000, _initialRetryDelayMs: 1000, _multiplier: 2, _jitterFactor: 0.2, _inFlightTimeoutIds: [] } }

Second session output. You'll notice that _open is set to false and "closed session" is printed directly afterwards:

Session { _mode: 'WRITE', _readConnectionHolder: ConnectionHolder { _mode: 'READ', _connectionProvider: DirectConnectionProvider { _hostPort: 'example.com:7687', _connectionPool: [Pool], _driverOnErrorCallback: [Function: bound _driverOnErrorCallback] }, _referenceCount: 0, _connectionPromise: Promise { null, domain: [Domain] } }, _writeConnectionHolder: ConnectionHolder { _mode: 'WRITE', _connectionProvider: DirectConnectionProvider { _hostPort: 'example.com:7687', _connectionPool: [Pool], _driverOnErrorCallback: [Function: bound _driverOnErrorCallback] }, _referenceCount: 0, _connectionPromise: Promise { undefined, domain: [Domain] } }, _open: false, _hasTx: false, _lastBookmark: Bookmark { _values: [ 'neo4j:bookmark:v1:tx34' ], _maxValue: 'neo4j:bookmark:v1:tx34' }, _transactionExecutor: TransactionExecutor { _maxRetryTimeMs: 30000, _initialRetryDelayMs: 1000, _multiplier: 2, _jitterFactor: 0.2, _inFlightTimeoutIds: [] } } closed session

Third. I also got "closed session" a second time, not sure why.

Session { _mode: 'WRITE', _readConnectionHolder: ConnectionHolder { _mode: 'READ', _connectionProvider: DirectConnectionProvider { _hostPort: 'example.com:7687', _connectionPool: [Pool], _driverOnErrorCallback: [Function: bound _driverOnErrorCallback] }, _referenceCount: 0, _connectionPromise: Promise { null, domain: [Domain] } }, _writeConnectionHolder: ConnectionHolder { _mode: 'WRITE', _connectionProvider: DirectConnectionProvider { _hostPort: 'example.com:7687', _connectionPool: [Pool], _driverOnErrorCallback: [Function: bound _driverOnErrorCallback] }, _referenceCount: 0, _connectionPromise: Promise { undefined, domain: [Domain] } }, _open: false, _hasTx: false, _lastBookmark: Bookmark { _values: [ 'neo4j:bookmark:v1:tx35' ], _maxValue: 'neo4j:bookmark:v1:tx35' }, _transactionExecutor: TransactionExecutor { _maxRetryTimeMs: 30000, _initialRetryDelayMs: 1000, _multiplier: 2, _jitterFactor: 0.2, _inFlightTimeoutIds: [] } } closed session

Fourth:

Session { _mode: 'WRITE', _readConnectionHolder: ConnectionHolder { _mode: 'READ', _connectionProvider: DirectConnectionProvider { _hostPort: 'example.com:7687', _connectionPool: [Pool], _driverOnErrorCallback: [Function: bound _driverOnErrorCallback] }, _referenceCount: 0, _connectionPromise: Promise { null, domain: [Domain] } }, _writeConnectionHolder: ConnectionHolder { _mode: 'WRITE', _connectionProvider: DirectConnectionProvider { _hostPort: 'example.com:7687', _connectionPool: [Pool], _driverOnErrorCallback: [Function: bound _driverOnErrorCallback] }, _referenceCount: 0, _connectionPromise: Promise { undefined, domain: [Domain] } }, _open: false, _hasTx: false, _lastBookmark: Bookmark { _values: [ 'neo4j:bookmark:v1:tx35' ], _maxValue: 'neo4j:bookmark:v1:tx35' }, _transactionExecutor: TransactionExecutor { _maxRetryTimeMs: 30000, _initialRetryDelayMs: 1000, _multiplier: 2, _jitterFactor: 0.2, _inFlightTimeoutIds: [] } }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions