neo4j-javascript-driver: Server keeps Expiring Session.

I’ve tried the following in node 7.3.0, 7.3.1 and 8.0.1:

import * as v1 from 'neo4j-driver';

const neo4j = v1.v1;
const auth = neo4j.auth.basic( 'neo4j', 'password' );
console.log( 'auth.basic returned: ' + JSON.stringify( auth ));
const driver = neo4j.driver( 'bolt://localhost', auth );
const session = driver.session();

const query = `
	CREATE (string:TEST:Type {name: 'String'})
	CREATE (int:TEST:Type {name: 'Int'})
	CREATE (id:TEST:Type {name: 'ID'})
	CREATE (query:TEST:Type {name: 'Query'})
	CREATE (mutation:TEST:Type {name: 'Mutation'})
	CREATE (subscription:TEST:Type {name: 'Subscription'})
	CREATE (author:TEST:Type {name: 'Author'})
	CREATE (post:TEST:Type {name: 'Post'})
	CREATE (comment:TEST:Type {name: 'Comment'})
`

session.run( { statements: query } )
	.then( ( result ) => {
		console.log( result );
	} )
	.catch( ( err ) => { console.log( err ); } );

That gives me (with debug on):

auth.basic returned: {"scheme":"basic","principal":"neo4j","credentials":"password"}
C:INIT "neo4j-javascript/0.0.0-dev" {"scheme":"basic","principal":"neo4j","credentials":"password"}
S:SUCCESS {"server":"Neo4j/3.1.0"}
C:RUN {"statements":"\n\tCREATE (string:TEST:Type {name: 'String'})\n\tCREATE (int:TEST:Type {name: 'Int'})\n\tCREATE (id:TEST:Type {name: 'ID'})\n\t
CREATE (query:TEST:Type {name: 'Query'})\n\tCREATE (mutation:TEST:Type {name: 'Mutation'})\n\tCREATE (subscription:TEST:Type {name: 'Subscription'})\
n\tCREATE (author:TEST:Type {name: 'Author'})"} {}
C:PULL_ALL
{ Error: Connection was closed by server
    at new Neo4jError (/Users/timhope/Dev/ts-koapollo/node_modules/neo4j-driver/lib/v1/error.js:65:132)
    at newError (/Users/timhope/Dev/ts-koapollo/node_modules/neo4j-driver/lib/v1/error.js:55:10)
    at NodeChannel._handleConnectionTerminated (/Users/timhope/Dev/ts-koapollo/node_modules/neo4j-driver/lib/v1/internal/ch-node.js:330:41)
    at emitNone (events.js:91:20)
    at TLSSocket.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9) code: 'SessionExpired' }

I thought maybe it was a bolt or server-side problem so I tried cypher-shell.

Same query through cypher-shell:

bash-3.2$ ./neo4j-community-3.1.0/bin/cypher-shell
username: neo4j
password: ********
Connected to Neo4j 3.1.0 at bolt://localhost:7687 as user neo4j.
Type :help for a list of available commands or :exit to exit the shell.
Note that Cypher queries must end with a semicolon.
neo4j> :help

Available commands:
  :begin    Open a transaction
  :commit   Commit the currently open transaction
  :exit     Exit the logger
  :help     Show this help message
  :history  Print a list of the last commands executed
  :param    Set the value of a query parameter
  :params   Prints all currently set query parameters and their values
  :rollback Rollback the currently open transaction

For help on a specific command type:
    :help command


For help on cypher please visit:
    https://neo4j.com/docs/developer-manual/3.1-beta/cypher/

neo4j> CREATE (string:TEST:Type {name: 'String'})
       CREATE (int:TEST:Type {name: 'Int'})
       CREATE (id:TEST:Type {name: 'ID'})
       CREATE (query:TEST:Type {name: 'Query'})
       CREATE (mutation:TEST:Type {name: 'Mutation'})
       CREATE (subscription:TEST:Type {name: 'Subscription'});
Added 9 nodes

I’m absolutely stumped, any help is much appreciated. I’m going mad. I’ve tried a million variations of starting and closing sessions and drivers to no avail.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (13 by maintainers)

Most upvoted comments

Hi @SnappyCroissant,

Both PRs are now merged. Error logging will be available in next neo4j 3.1.1 and 3.2. Parameter type checks will be available in JS driver 1.1.0 or 1.2.

Thanks for your help!

I’m just going to add in here that its extremely important to note where exactly session.close() or driver.close() are because these are generally asynchronous operations written synchronously.

If your driver.close() isn’t nested inside something, there is a strong chance the entire script runs and closes the driver before it gets to code that is chained. I’m not saying its happening here, although the original poster did say he had a driver.close() firing at the end, but I didn’t see it in his example, so it is mildly suspect.

I’m just including this for people searching later. I say this because the true error is: Error: Connection was closed by server.