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.