I am using .NET Driver for Neo4j .
Environment: .NET 6 Neo4j Server version : 4.3.2 Driver version : Neo4j.Driver 4.4.0
We are using a singleton driver connection with the server using the following code snippet and reusing it across all the sessions.
Neo4j.Driver.IDriver _driver = GraphDatabase.Driver("neo4j://*.*.*.*:7687", AuthTokens.Basic("neo4j", "*****"));
And we are opening and closing a session with each transaction like
var session = _driver.AsyncSession(o => o.WithDatabase("pdb00"));
try
{
return await session.ReadTransactionAsync(async tx =>
{
var result = await tx.RunAsync
(
query, parameters
);
res = await result.ToListAsync();
var counters = await result.ConsumeAsync();
Console.WriteLine("Time taken to read query " + index + ": " + counters.ResultConsumedAfter.TotalMilliseconds);
return res;
});
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
throw;
}
finally
{
await session.CloseAsync();
}
However when we monitor the number of active connections to the Neo4j server using the following command
call dbms.listConnections()
We are seeing as many connections as the number of sessions that are made, and the connections are not getting dropped until the Driver is closed.
For instance, if we call the transaction 100 times, the active connections increase by 100, and they are staying as-is even though session.closeasync() is getting invoked per session.
And only after Driver.closeAsync() is invoked at the application end, all the connections are dropped.
On heavy load, we are running into server overloading and port exhaustion scenarios due to this behavior.
Snapshot of current connections: Neo4j browser snapshot
Are we missing something here ?
Thanks in advance.