andreasronge/neo4j-core — pull request #23 by dwbutler (2013-01-24 19:19:25+00:00)
Title: Thread-safe Neo4j.start

As discussed in https://github.com/andreasronge/neo4j/issues/237, it seems Neo4j.start is not currently thread-safe. This fix solves the issue for me in both puma and torquebox-lite.

There were two problems:
* There was no lock around ```Neo4j::Core::Database#start```, which allowed other threads concurrent access to this method. This fix introduces a lock around the whole method.
* ```@running``` was set to true in ```Neo4j::Core::Database``` before the database had actually completed start up. Since other threads check for ```db.running?```, this caused these threads to access the database before it had actually completed initializing. This is now fixed by setting ```@running``` to true only after the database has finished initializing.

It turned out to be unnecessary to put a lock around ```Neo4j.start```. In fact, doing so caused problems. (Please ignore the whitespace changes in neo4j.rb - I had trouble cleaning up my git history.)