Issue #9257 has been reported by ngoto (Naohisa Goto).

----------------------------------------
Bug #9257: flock OS dependency problem in RubyGems
https://bugs.ruby-lang.org/issues/9257

Author: ngoto (Naohisa Goto)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v: ruby 2.1.0dev (2013-12-16)
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


On Solaris, after r44517, many tests of RubyGems failed or raise error during make test-all.

For example,

  44) Failure:
 TestGemDependencyInstaller#test_install_security_policy [/XXX/test/rubygems/test_gem_dependency_installer.rb:846]:
 [Gem::Security::Exception] exception expected, not
 Class: <Errno::EBADF>
 Message: <"Bad file number @ rb_file_flock - /var/tmp/test_rubygems_21075/spec_c
ache/gems.example.com%80/quick/Marshal.4.8/b-1.gemspec">
 ---Backtrace---
 /XXX/lib/rubygems.rb:768:in `flock'
 /XXX/lib/rubygems.rb:768:in `block in read_binary'
 /XXX/lib/rubygems.rb:767:in `open'
 /XXX/lib/rubygems.rb:767:in `read_binary'
 /XXX/lib/rubygems/source.rb:133:in `fetch_spec'
 /XXX/lib/rubygems/resolver/index_specification.rb:64:in `spec'
 /XXX/lib/rubygems/resolver/specification.rb:85:in `installable_platform?'
 /XXX/lib/rubygems/platform.rb:34:in `installable?'
 /XXX/lib/rubygems/resolver.rb:426:in `block in select_local_platforms'
 /XXX/lib/rubygems/resolver.rb:425:in `select'
 /XXX/lib/rubygems/resolver.rb:425:in `select_local_platforms'
 /XXX/lib/rubygems/resolver.rb:200:in `find_possible'
 /XXX/lib/rubygems/resolver.rb:327:in `resolve_for'
 /XXX/lib/rubygems/resolver.rb:165:in `resolve'
 /XXX/lib/rubygems/request_set.rb:238:in `resolve'
 /XXX/lib/rubygems/dependency_installer.rb:434:in `resolve_dependencies'
 /XXX/lib/rubygems/dependency_installer.rb:371:in `install'
 /XXX/test/rubygems/test_gem_dependency_installer.rb:847:in `block in test_install_security_policy'
---------------

  46) Error:
 TestGemResolverLockSpecification#test_install:
 Errno::EBADF: Bad file number @ rb_file_flock - /var/tmp/test_rubygems_21075/gems/a-2.gem
    /XXX/lib/rubygems.rb:768:in `flock'
    /XXX/lib/rubygems.rb:768:in `block in read_binary'
    /XXX/lib/rubygems.rb:767:in `open'
    /XXX/lib/rubygems.rb:767:in `read_binary'
    /XXX/lib/rubygems/test_utilities.rb:328:in `block in setup_fetcher'
    /XXX/lib/rubygems/test_utilities.rb:324:in `each'
    /XXX/lib/rubygems/test_utilities.rb:324:in `setup_fetcher'
    /XXX/lib/rubygems/test_utilities.rb:247:in `execute'
    /XXX/lib/rubygems/test_utilities.rb:207:in `declare'
    /XXX/lib/rubygems/test_case.rb:1207:in `spec_fetcher'
    /XXX/test/rubygems/test_gem_resolver_lock_specification.rb:36:in `test_install'

The failures/errors is caused in line 768 in lib/rubygems.rb,
in the self.read_binary method.

  def self.read_binary(path)
    File.open path, binary_mode do |f|
      f.flock(File::LOCK_EX)
      f.read
    end
  end

On Solaris (and probably on JRuby), files opened with read-only mode can not be exclusively locked by using flock.

FYI, when similar problem was found in Rails, the solution was to open the file with read-write mode.
https://rails.lighthouseapp.com/projects/8994/tickets/6662-fileflock-cant-lock-read-only-file-for-exclusive-access



-- 
http://bugs.ruby-lang.org/