Skip to content

Conversation

@lutovich
Copy link
Contributor

@lutovich lutovich commented Nov 29, 2016

It was previously possible to use closed driver instance, obtain sessions from it and run queries. This was seen to cause problems in multi-threaded scenarios when some worker threads try to use driver, which was concurrently closed by other worker.
This commit makes driver track if it is closed or not and throw exceptions if on every interaction when closed. Thrown exception is IllegalStateException. Actuall #close() method can be called multiple times and is a no-op for already closed driver.

@lutovich
Copy link
Contributor Author

PR introduces a ReadWriteLock in driver to disallow #close() and #session() run concurrently. To ensure that it does not affect performance this JMH benchmark was used:

@Benchmark
public Session session() {
    Session session = driver.session();
    session.close();
    return session;
}

Results with 1 thread:

Benchmark                  Mode  Cnt   Score   Error   Units
sessionOpenCloseCurrent   thrpt  150  21.926 ± 0.508  ops/ms
sessionOpenCloseWithLock  thrpt  150  21.750 ± 0.537  ops/ms

Results with 8 threads:

Benchmark                  Mode  Cnt   Score   Error   Units
sessionOpenCloseCurrent   thrpt  150  60.869 ± 3.324  ops/ms
sessionOpenCloseWithLock  thrpt  150  61.202 ± 3.614  ops/ms

So it looks like lock does not reduce performance, at least for the used configuration.

It was previously possible to use closed driver instance, obtain sessions from
it and run queries. This was seen to cause problems in multi-threaded scenarios
when some worker threads try to use driver, which was concurrently closed by
other worker.

This commit makes driver track if it is closed or not and throw exceptions if
on every interaction when closed. Thrown exception is `IllegalStateException`.
Actuall `#close()` method can be called multiple times and is a no-op for
already closed driver.
@zhenlineo zhenlineo merged commit e6c9976 into neo4j:1.1 Nov 29, 2016
@lutovich lutovich deleted the 1.1-closed-driver branch November 29, 2016 22:27
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

Successfully merging this pull request may close these issues.

2 participants