Skip to content

Server keeps Expiring Session. #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TimothyMischief opened this issue Jan 6, 2017 · 17 comments
Closed

Server keeps Expiring Session. #187

TimothyMischief opened this issue Jan 6, 2017 · 17 comments

Comments

@TimothyMischief
Copy link
Contributor

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.

@lutovich
Copy link
Contributor

lutovich commented Jan 6, 2017

Hi @SnappyCroissant,

Does this happen every time you run the query? Did you check neo4j database log when this error happens?

@TimothyMischief
Copy link
Contributor Author

It's happening with all queries executed through the driver, every time.

neo4j.log, debug.log all read nothing.

query.log isn't generating despite being turned on. Neither from the cypher-shell queries or the ones coming from node. Threshold is set to 0 so it should be getting everything.

@TimothyMischief
Copy link
Contributor Author

I've tried to recreate the issue in a fresh project and I can't. I'm thinking it's something in the project setup somewhere breaking it. For the moment I've switched to REST, this project won't see production so efficiency isn't mission critical. When I get some time though I'll see if I can isolate the problem incase anyone else runs into it.

@lutovich
Copy link
Contributor

@SnappyCroissant are you using the same database instance in the fresh project? do you ever close sessions (your example does not have session.close call)?

@TimothyMischief
Copy link
Contributor Author

In the original code that failed before I started reconfiguring to test there was a session.close call in .then and .catch. I missed them when running the examples above but still had a driver.close running on exit. And I've added session.close calls back in .then and .catch

I tried the fresh project on a new instance and the same one, same results.

I played around with it some more and got the vanilla node version working inside the original project after wiping and reinstalling all npm modules incase I'd broken somethign unknowingly going through turning on logs and playing with typings and such. But it still breaks the same way within the project so I'm thinking there's a conflict somewhere around transpiling, streams or next tick that's corrupting something on the way to the server and back.

I've started stripping things back layer by layer. Starting at where I first encountered the problem.

First encounter conditions:

  • Running tests in mocha through ts-node with nyc watching for coverage

  • Stopped running inside NYC

  • Ran transpiled JS rather than inside ts-node

  • Removed Typescript decorators from mocha-typescript

Next step is to run outside of mocha but trying to isolate the production code. Then switching from transpiled es6 imports to require statements. I've already run the script as part of the larger project which has been failing from the start. But I want to pull things out piece by piece. At the moment though none of those changes have changed anything.

It's really got me stumped. There's got to be some strange conflict somewhere. I'm definitely moving away from typescript in further projects. I've got a hobby project at home running pure node with harmony flags that is working brilliantly with this module. This combined with async await is a dream.

@lutovich
Copy link
Contributor

@SnappyCroissant could you maybe create a github repo with a project that reproduces the problem? We can then take a look as well.

@TimothyMischief
Copy link
Contributor Author

You can find it here: https://github.com/SnappyCroissant/ts-koapollo

I've cleaned it up a little and left some notes in the readme.

@lutovich
Copy link
Contributor

Thanks @SnappyCroissant! We will take a look.

@lutovich
Copy link
Contributor

lutovich commented Jan 20, 2017

Hi @SnappyCroissant,

I created a PR with tentative fix for this problem: https://github.com/SnappyCroissant/ts-koapollo/pull/1.

Problem happened because of session.run( { statements: query } ). This function expects first argument to be string. Second argument is optional and can be an object of query parameters. Driver does not check the type of the first query argument so it tried to send object to the server as is. This caused a protocol violation on the server and it immediately closed the connection.

I can't fully verify the fix because project does not build. Some TypeScript errors...

We need to improve logging in the database and possibly verify types in session.run arguments.

Please let me know if this helps.

@TimothyMischief
Copy link
Contributor Author

That's worked! I'm not sure where I got that structure for parameters, or how I managed to miss it. Maybe from early attempts with other libraries it got left over. I'm glad something has come of my mistake though.

Thanks for all your help!

@lutovich
Copy link
Contributor

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!

@Prateek218
Copy link

Prateek218 commented May 18, 2017

Hi @SnappyCroissant and @lutovich
I'm facing the same issue can you plz help me and tell me where I can find the solution.
I'm new to neo4j and node plz help me

@lutovich
Copy link
Contributor

Hi @Prateek218, could you please share more info about your project? Maybe share code you use to query the database?

This particular issue happened because session.run({statements: query}) can't be used and simple session.run(query) should be used instead.

@Prateek218
Copy link

Prateek218 commented May 19, 2017

This my code, database log, and server error.

express           =     require('express')
  ,	neo4j_match 			  = 	require('neo4j')
   , session           =     require('express-session')
  , bodyParser        =     require('body-parser')
  , moment            =     require('moment')
  , request           =     require('request')
  , app               =     express();
  var every = require('every-moment');
  var neo4j = require('neo4j-driver').v1;
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({extended: true}));
  var db = new neo4j_match.GraphDatabase('http://neo4j:neo4j@localhost:7474');
var driver = neo4j.driver("bolt://localhost:7687", neo4j.auth.basic("neo4j", "neo4j"));
var session = driver.session();
  every(40, 'seconds', function() {
 
session
  .run('match (c:channel) where c.from="yt" return c')
  .then(function(result){
    return result.records.map(function(record){
      return {
        title: record._fields[0].properties.channelid
      };
    })
    session.close();
  })
  .then(function(cron_channel){
    for (var k in cron_channel){
       (function(k){
          console.log(cron_channel[k].title);
          request('https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=50&channelId='+cron_channel[k].title+'&order=date&key=AIzaSyBj7mztzfuZq_LA_5TYHLAw-Qaa2Fof3JU', function (error, response, body) {
  if (!error && response.statusCode == 200) {
  body=JSON.parse(body);

  for(var i in body.items){
    (function(i){
    //selecting video id and getting their meta data
    request('https://www.googleapis.com/youtube/v3/videos?part=statistics,snippet,contentDetails&id='+body.items[i].id.videoId+'&key=AIzaSyBj7mztzfuZq_LA_5TYHLAw-Qaa2Fof3JU',function(err, res, vid){
    if (!error && res.statusCode == 200){
    vid=JSON.parse(vid);
    for(var j in vid.items){
        (function(j){
      //node creation 
      if(vid.items[j].statistics.likeCount == null){
        db.cypher({
    query: 'match (a:channel) where a.channelid={channelParam} merge (n:video {id:{idParam}, categoryid:{categoryidParam}, title:{titleParam}, description:{descriptionParam}, created_time:{created_timeParam},category:a.category, source:{channelParam}, length:{lengthParam}, video_thumbnail:{video_thumbnailParam}, from:"yt"}) ON CREATE SET n.language=a.language, n.views={viewCountParam}, n.likes={likeCountParam}, n.android_views=0, n.android_likes=0, n.created_at=timestamp() ON MATCH SET n.views={viewCountParam}, n.likes={likeCountParam} RETURN n',
params: {
        idParam:vid.items[j].id,
        titleParam:vid.items[j].snippet.title, 
        categoryidParam:vid.items[j].snippet.categoryId,
        descriptionParam:vid.items[j].snippet.description,
        created_timeParam:vid.items[j].snippet.publishedAt, 
        channelParam:cron_channel[k].title, 
        lengthParam:moment.duration(vid.items[j].contentDetails.duration).asMilliseconds(),
        viewCountParam:vid.items[j].statistics.viewCount,
        likeCountParam:0, 
        video_thumbnailParam:vid.items[j].snippet.thumbnails.high.url
},
},
function (err, results) {
    if (err) throw err;
    var result = results[0];
    if (!result) {
        console.log('No user found.');
    } else {
        console.log("success");
    }
    
});
      }
      else if(vid.items[j].statistics.viewCount == null){
           db.cypher({
    query: 'match (c:channel), (v:video), (u:user) where (v.source=c.channelid OR v.source=c.title) AND c.channelid={channel_id} AND u.title={userid} optional match (u:user)-[r:like]-(v) optional match (u:user)-[re:repick]-(v) RETURN v.title,v.id, v.created_time,v.likes,v.views,v.android_likes, v.android_views,v.from,c.title, c.channelid,c.channelthumbnail,c.followers, c.video_count,r.title ,re.title ORDER BY v.created_time LIMIT 200',
params: {
        idParam:vid.items[j].id,
        titleParam:vid.items[j].snippet.title,
        descriptionParam:vid.items[j].snippet.description, 
        categoryidParam:vid.items[j].snippet.categoryId,
        created_timeParam:vid.items[j].snippet.publishedAt,
        channelParam:cron_channel[k].title, 
        lengthParam:moment.duration(vid.items[j].contentDetails.duration).asMilliseconds(),
        viewCountParam:0,
        likeCountParam:vid.items[j].statistics.likeCount, 
        video_thumbnailParam:vid.items[j].snippet.thumbnails.high.url
},
},
function (err, results) {
    if (err) throw err;
    var result = results[0];
    if (!result) {
        console.log('No user found.');
    } else {
        console.log("success");
    }
});
      }
      else if(vid.items[j].statistics.viewCount == null && vid.items[j].statistics.likeCount == null){

db.cypher({
    query: 'match (a:channel) where a.channelid={channelParam} merge (n:video {id:{idParam}, categoryid:{categoryidParam}, title:{titleParam}, description:{descriptionParam}, created_time:{created_timeParam},category:a.category, source:{channelParam}, length:{lengthParam}, video_thumbnail:{video_thumbnailParam}, from:"yt"}) ON CREATE SET n.language=a.language, n.views={viewCountParam}, n.likes={likeCountParam}, n.android_views=0, n.android_likes=0, n.created_at=timestamp() ON MATCH SET n.views={viewCountParam}, n.likes={likeCountParam} RETURN n',
params: {
        idParam:vid.items[j].id,
        titleParam:vid.items[j].snippet.title,
        descriptionParam:vid.items[j].snippet.description, 
        categoryidParam:vid.items[j].snippet.categoryId,
        created_timeParam:vid.items[j].snippet.publishedAt, 
        channelParam:cron_channel[k].title, 
        lengthParam:moment.duration(vid.items[j].contentDetails.duration).asMilliseconds(),
        viewCountParam:0, 
        likeCountParam:0, 
        video_thumbnailParam:vid.items[j].snippet.thumbnails.high.url
},
},
function (err, results) {
    if (err) throw err;
    var result = results[0];
    if (!result) {
        console.log('No user found.');
    } else {
         console.log("success");
    }
});

      }
      else{
      db.cypher({
    query: 'match (a:channel) where a.channelid={channelParam} merge (n:video {id:{idParam}, title:{titleParam}, categoryid:{categoryidParam}, description:{descriptionParam}, created_time:{created_timeParam},category:a.category, source:{channelParam}, length:{lengthParam}, video_thumbnail:{video_thumbnailParam}, from:"yt"}) ON CREATE SET n.language=a.language, n.views={viewCountParam}, n.likes={likeCountParam}, n.android_views=0, n.android_likes=0, n.created_at=timestamp() ON MATCH SET n.views={viewCountParam}, n.likes={likeCountParam} RETURN n',
params: {
        idParam:vid.items[j].id,
        titleParam:vid.items[j].snippet.title,
        descriptionParam:vid.items[j].snippet.description, 
        categoryidParam:vid.items[j].snippet.categoryId,
        created_timeParam:vid.items[j].snippet.publishedAt,
        channelParam:cron_channel[k].title, 
        lengthParam:moment.duration(vid.items[j].contentDetails.duration).asMilliseconds(),
        viewCountParam:vid.items[j].statistics.viewCount, 
        likeCountParam:vid.items[j].statistics.likeCount, 
        video_thumbnailParam:vid.items[j].snippet.thumbnails.high.url
},
},
function (err, results) {
    if (err) throw err;
    var result = results[0];
    if (!result) {
        console.log('No user found.');
    } else {
        console.log("success");
    }
});
}
  session
  .run('match (a:video), (b:language) where a.language=b.title merge (b)-[r:video_lang{title:"video_lang"}]-(a) return a,b,r ')
  .then(function(result){
    console.log("success1");
    session.close();
  })
  .catch(function(err){
    console.log(err);
  });

  //relation creation
  session
  .run('match (a:channel), (b:video) where a.channelid={channelParam} AND b.source={channelParam} merge (a)-[r:rel_video{title:"yt"}]->(b) return a,b,r',{channelParam:cron_channel[k].title})
  .then(function(result){
    console.log("success2");
    session.close();
  })
  .catch(function(err){
    console.log(err);
  });
        })(j);
        }
                }
    })  
})(i);
}//first for
  }
})

       })(k);


}


    
  }); 
});
)

Database log

2017-05-18 16:09:16.849+0000 ERROR [o.n.b.t.SocketTransportHandler] Fatal error occurred when handling a client connection: failed to allocate 16777216 byte(s) of direct memory (used: 922746887, max: 934281216) failed to allocate 16777216 byte(s) of direct memory (used: 922746887, max: 934281216)
io.netty.util.internal.OutOfDirectMemoryError: failed to allocate 16777216 byte(s) of direct memory (used: 922746887, max: 934281216)
at io.netty.util.internal.PlatformDependent.incrementMemoryCounter(PlatformDependent.java:624)
at io.netty.util.internal.PlatformDependent.allocateDirectNoCleaner(PlatformDependent.java:578)
at io.netty.buffer.PoolArena$DirectArena.allocateDirect(PoolArena.java:709)
at io.netty.buffer.PoolArena$DirectArena.newChunk(PoolArena.java:698)
at io.netty.buffer.PoolArena.allocateNormal(PoolArena.java:237)
at io.netty.buffer.PoolArena.allocate(PoolArena.java:221)
at io.netty.buffer.PoolArena.allocate(PoolArena.java:141)
at io.netty.buffer.PooledByteBufAllocator.newDirectBuffer(PooledByteBufAllocator.java:262)
at io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:179)
at io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:170)
at io.netty.buffer.AbstractByteBufAllocator.buffer(AbstractByteBufAllocator.java:107)
at io.netty.handler.ssl.SslHandler.allocate(SslHandler.java:1472)
at io.netty.handler.ssl.SslHandler.allocateOutNetBuf(SslHandler.java:1482)
at io.netty.handler.ssl.SslHandler.wrap(SslHandler.java:519)
at io.netty.handler.ssl.SslHandler.flush(SslHandler.java:490)
at io.netty.channel.AbstractChannelHandlerContext.invokeFlush0(AbstractChannelHandlerContext.java:787)
at io.netty.channel.AbstractChannelHandlerContext.invokeFlush(AbstractChannelHandlerContext.java:779)
at io.netty.channel.AbstractChannelHandlerContext.access$1500(AbstractChannelHandlerContext.java:39)
at io.netty.channel.AbstractChannelHandlerContext$WriteAndFlushTask.write(AbstractChannelHandlerContext.java:1148)
at io.netty.channel.AbstractChannelHandlerContext$AbstractWriteTask.run(AbstractChannelHandlerContext.java:1089)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:418)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:454)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:873)
at java.lang.Thread.run(Unknown Source)
2017-05-18 16:09:16.937+0000 WARN [io.netty.channel.AbstractChannelHandlerContext] Failed to mark a promise as failure because it has succeeded already: DefaultChannelPromise@3c0b7552(success)

server log

{ Error: Connection was closed by server
at Neo4jError.Error (native)
at new Neo4jError (C:\Users\Prateek\Desktop\Youtube Cron\node_modules\neo4j-driver\lib\v1\error.js:76:132)
at newError (C:\Users\Prateek\Desktop\Youtube Cron\node_modules\neo4j-driver\lib\v1\error.js:66:10)
at NodeChannel._handleConnectionTerminated (C:\Users\Prateek\Desktop\Youtube Cron\node_modules\neo4j-driver\lib\v1\internal\ch-node.js:336: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: 'ServiceUnavailable' }

Database log

2017-05-18 1:09:16.849+0000 ERROR [o.n.b.t.SocketTransportHandler] Fatal error occurred when handling a client connection: failed to allocate 16777216 byte(s) of direct memory (used: 922746887, max: 934281216) failed to allocate 16777216 byte(s) of direct memory (used: 922746887, max: 934281216)
io.netty.util.internal.OutOfDirectMemoryError: failed to allocate 16777216 byte(s) of direct memory (used: 922746887, max: 934281216)
at io.netty.util.internal.PlatformDependent.incrementMemoryCounter(PlatformDependent.java:624)
at io.netty.util.internal.PlatformDependent.allocateDirectNoCleaner(PlatformDependent.java:578)
at io.netty.buffer.PoolArena$DirectArena.allocateDirect(PoolArena.java:709)
at io.netty.buffer.PoolArena$DirectArena.newChunk(PoolArena.java:698)
at io.netty.buffer.PoolArena.allocateNormal(PoolArena.java:237)
at io.netty.buffer.PoolArena.allocate(PoolArena.java:221)
at io.netty.buffer.PoolArena.allocate(PoolArena.java:141)
at io.netty.buffer.PooledByteBufAllocator.newDirectBuffer(PooledByteBufAllocator.java:262)
at io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:179)
at io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:170)
at io.netty.buffer.AbstractByteBufAllocator.buffer(AbstractByteBufAllocator.java:107)
at io.netty.handler.ssl.SslHandler.allocate(SslHandler.java:1472)
at io.netty.handler.ssl.SslHandler.allocateOutNetBuf(SslHandler.java:1482)
at io.netty.handler.ssl.SslHandler.wrap(SslHandler.java:519)
at io.netty.handler.ssl.SslHandler.flush(SslHandler.java:490)
at io.netty.channel.AbstractChannelHandlerContext.invokeFlush0(AbstractChannelHandlerContext.java:787)
at io.netty.channel.AbstractChannelHandlerContext.invokeFlush(AbstractChannelHandlerContext.java:779)
at io.netty.channel.AbstractChannelHandlerContext.access$1500(AbstractChannelHandlerContext.java:39)
at io.netty.channel.AbstractChannelHandlerContext$WriteAndFlushTask.write(AbstractChannelHandlerContext.java:1148)
at io.netty.channel.AbstractChannelHandlerContext$AbstractWriteTask.run(AbstractChannelHandlerContext.java:1089)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:418)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:454)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:873)
at java.lang.Thread.run(Unknown Source)
2017-05-18 16:09:16.937+0000 WARN [io.netty.channel.AbstractChannelHandlerContext] Failed to mark a promise as failure because it has succeeded already: DefaultChannelPromise@3c0b7552(success)

server log
{ Error: Connection was closed by server
at Neo4jError.Error (native)
at new Neo4jError (C:\Users\Prateek\Desktop\Youtube Cron\node_modules\neo4j-driver\lib\v1\error.js:76:132)
at newError (C:\Users\Prateek\Desktop\Youtube Cron\node_modules\neo4j-driver\lib\v1\error.js:66:10)
at NodeChannel._handleConnectionTerminated (C:\Users\Prateek\Desktop\Youtube Cron\node_modules\neo4j-driver\lib\v1\internal\ch-node.js:336: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: 'ServiceUnavailable' }

@lutovich
Copy link
Contributor

@Prateek218 I see you also created a separate issue #244. Let's move our discussion there. Will go through the code now.

@amackintosh
Copy link

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.

@tatva122
Copy link

tatva122 commented Aug 5, 2021

Hi
@lutovich @amackintosh
Some time I am getting error when run query.

Neoj4 : v4.2.0
Node JS: v12.16.1
neo4j-driver (Javascript) : v4.0.2

neo4j-URI: neo4j+s://example.databases.neo4j.io:7687

`Neo4jError: Connection was closed by server

at captureStacktrace (/var/example.com/httpdocs/api/node_modules/neo4j-driver/lib/result.js:277:15)
at new Result (/var/example.com/httpdocs/api/node_modules/neo4j-driver/lib/result.js:68:19)
at Session._run (/var/example.com/httpdocs/api/node_modules/neo4j-driver/lib/session.js:174:14)
at Session.run (/var/example.com/httpdocs/api/node_modules/neo4j-driver/lib/session.js:135:19)
at Object.run (/var/example.com/httpdocs/api/src/utils/db.js:24:6)
at processTicksAndRejections (internal/process/task_queues.js:97:5) {

code: 'SessionExpired',
name: 'Neo4jError'
}`

I am using executeQuery.run(driver, query, params) layer for execute query;

const checkConnection = async (dbDriver) => { let connected = true; try { await dbDriver.verifyConnectivity(); } catch (error) { console.error(connectivity verification failed. ${error}); connected = false; } return connected; };

const run = async (dbDriver, query, params = {}) => { await checkConnection(dbDriver); if (query && query.length === 0) { return null; } const session = dbDriver.session(); return session .run(query, params) .then((result) => { session.close(); return result; }) .catch((err) => { session.close(); throw err; }); };

Can you please help me to fix "SessionExpired" issue ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants