Bug #9257
closedflock OS dependency problem in RubyGems
Description
On Solaris, after r44157, many tests of RubyGems failed or raise error during make test-all.
For example,
- 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:inflock' /XXX/lib/rubygems.rb:768:inblock in read_binary'
 /XXX/lib/rubygems.rb:767:inopen' /XXX/lib/rubygems.rb:767:inread_binary'
 /XXX/lib/rubygems/source.rb:133:infetch_spec' /XXX/lib/rubygems/resolver/index_specification.rb:64:inspec'
 /XXX/lib/rubygems/resolver/specification.rb:85:ininstallable_platform?' /XXX/lib/rubygems/platform.rb:34:ininstallable?'
 /XXX/lib/rubygems/resolver.rb:426:inblock in select_local_platforms' /XXX/lib/rubygems/resolver.rb:425:inselect'
 /XXX/lib/rubygems/resolver.rb:425:inselect_local_platforms' /XXX/lib/rubygems/resolver.rb:200:infind_possible'
 /XXX/lib/rubygems/resolver.rb:327:inresolve_for' /XXX/lib/rubygems/resolver.rb:165:inresolve'
 /XXX/lib/rubygems/request_set.rb:238:inresolve' /XXX/lib/rubygems/dependency_installer.rb:434:inresolve_dependencies'
 /XXX/lib/rubygems/dependency_installer.rb:371:ininstall' /XXX/test/rubygems/test_gem_dependency_installer.rb:847:inblock in test_install_security_policy'
- 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:inflock' /XXX/lib/rubygems.rb:768:inblock in read_binary'
 /XXX/lib/rubygems.rb:767:inopen' /XXX/lib/rubygems.rb:767:inread_binary'
 /XXX/lib/rubygems/test_utilities.rb:328:inblock in setup_fetcher' /XXX/lib/rubygems/test_utilities.rb:324:ineach'
 /XXX/lib/rubygems/test_utilities.rb:324:insetup_fetcher' /XXX/lib/rubygems/test_utilities.rb:247:inexecute'
 /XXX/lib/rubygems/test_utilities.rb:207:indeclare' /XXX/lib/rubygems/test_case.rb:1207:inspec_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
        
           Updated by ngoto (Naohisa Goto) almost 12 years ago
          Updated by ngoto (Naohisa Goto) almost 12 years ago
          
          
        
        
      
      - Description updated (diff)
        
           Updated by drbrain (Eric Hodel) almost 12 years ago
          Updated by drbrain (Eric Hodel) almost 12 years ago
          
          
        
        
      
      - Status changed from Open to Assigned
- Assignee set to drbrain (Eric Hodel)
I will fix this tonight, Pacific Time.
        
           Updated by drbrain (Eric Hodel) almost 12 years ago
          Updated by drbrain (Eric Hodel) almost 12 years ago
          
          
        
        
      
      - Status changed from Assigned to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r44286.
Naohisa, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
- 
lib/rubygems: Update to RubyGems master af60443. Changes include: - 
Improved speed of gem install --ignore-dependencies.
- 
Open read-write for exclusive flock. [ruby-trunk - Bug #9257] 
- 
Remove specification before install to prevent infinite loop. 
 
-