This project is archived and is in readonly mode.
File#flock can't lock read-only File for exclusive access
Reported by Charles Oliver Nutter | April 1st, 2011 @ 10:12 AM
On Solaris and (recently) on JRuby, File#flock will raise EBADF when attempting to acquire an exclusive lock on a File that has only been opened for read.
The case I have found is here: https://github.com/rails/rails/blob/master/activesupport/lib/active...
The filename specified is opened for read only, and then an exclusive lock is attempted.
MRI (all versions) on Solaris will raise EBADF for this case. There may be other platforms that behave the same.
On Java, all platforms will raise an error when attempting to acquire an exclusive lock on a file opened only for read. Up until recently, JRuby was downgrading exclusive locks to shared locks under these circumstances. This was pointed out as a very bad thing to do (giving a shared lock when an exclusive lock was requested), and so we now behave like MRI on Solaris regardless of what platform we run on.
The related JRuby bug is here: http://jira.codehaus.org/browse/JRUBY-5627
JRuby's "stable Rails" CI started failing after this bug was fixed: http://ci.jruby.org/job/rails-3-0-stable/component=activesupport,la...
One possible fix would be to attempt to open the file read/write before acquiring the lock. All cases in our "stable" version of Rails appear to be from active_support/cache/strategy/local_cache.rb, but that appears to no longer call file_lock directly. I have not done any further investigation on Rails master.
Comments and changes to this ticket
-
Arun Agrawal April 18th, 2011 @ 12:41 PM
- Tag set to jruby
- Assigned user set to rails
Pull request for this solution is here
-
Arun Agrawal April 18th, 2011 @ 12:43 PM
https://github.com/rails/rails/pull/288
Passes test with
Jruby-1.6.0
Jruby-1.6.1
ruby-1.9.2
ruby-1.8.7
ree -
Aaron Patterson April 18th, 2011 @ 05:09 PM
- State changed from new to committed
- Assigned user changed from rails to Aaron Patterson
- Importance changed from to Low
Fixed in master and 3-0-stable. This patch will be released with 3.0.8.
Thanks.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>