Synchronize read and modification of @reserved_connections #6398
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I am running JRuby 1.6.7 (1.6.6 locally) on Glassfishv3, OpenJDK. I am running a Rack
application that uses ActiveRecord 3.0.12 and/or 3.2.3. Glassfish
maintains a thread pool which it uses to service HTTP requests in a
multithreaded fashion. I am running into concurrency problems.
I have created a small JRuby-only test script that, at least on my
machine, reliably triggers the error. The script sets up active
record and then in a thread pool with 32 threads acquires and releases
connections from the connection pool.
With activerecord 3.2.3 and master (2012-05-19) I see the following error:
After applying my patch, I do not get the concurrency error. I am
also able to run the test suite for sqlite3 and postgresql.
After this patch, I do get another error with connection timeouts that
I am also seeing on my Glassfish system:
I believe it happens because the connection pool queue does not grant
a newly available connection to the first waiter in the queue. But
I'll leave for a future bug report; I'm yet not sure if ActiveRecord
or JRuby is at fault.
Here is the test script. The expected output is nothing. It prints
any exceptions that are raised. It runs for a long time, and may or
may not be able to reproduce the concurrency error, but on my system
it does reproduce it reliably. I'm not sure how to turn this script into a useful unit test,
mostly since it needs to run for a "long time" to even trigger the bug.
Any suggestions?
Executed like this:
The Gemfile:
The script itself: