在安装gem时出现"gem install Errno::ENOLCK"错误

4
每当我尝试使用gem install [gem-name]安装gem时,都会出现以下错误:
ERROR:  While executing gem ... (Errno::ENOLCK)
    No locks available @ rb_file_flock - /home/abod/.gem/specs/api.rubygems.org%443/quick/Marshal.4.8/bundler-1.7.12.gemspec

我只是为了说明问题而运行了 gem install bundler 命令,但无论我尝试安装什么 gem,都会出现 Errno::ENOLCK 错误。我已经搜索了很多资料,但似乎找不到任何关于这个错误的信息。

以下是 gem env 命令输出的内容,希望可以帮忙解决问题。

RubyGems Environment:
  - RUBYGEMS VERSION: 2.4.5
  - RUBY VERSION: 2.2.0 (2014-12-25 patchlevel 0) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/abod/.rvm/gems/ruby-2.2.0@global
  - RUBY EXECUTABLE: /home/abod/.rvm/rubies/ruby-2.2.0/bin/ruby
  - EXECUTABLE DIRECTORY: /home/abod/.rvm/gems/ruby-2.2.0@global/bin
  - SPEC CACHE DIRECTORY: /home/abod/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /home/abod/.rvm/rubies/ruby-2.2.0/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/abod/.rvm/gems/ruby-2.2.0@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /home/abod/.rvm/gems/ruby-2.2.0@global/bin
     - /home/abod/.rvm/rubies/ruby-2.2.0/bin
     - /usr/local/bin
     - /usr/bin
     - /usr/local/sbin
     - /usr/sbin
     - /home/abod/.rvm/bin
     - /home/abod/.rvm/bin

根据@joelparkerhenderson的建议,以下是一些可能有用的命令输出。

$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 2063389
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 32768
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 2063389
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited


$ uname -a
Linux biohen36 3.14.23-100.fc19.x86_64 #1 SMP Thu Oct 30 18:36:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

$ stat /home/abod/.gem/specs/api.rubygems.org%443/quick/Marshal.4.8/bundler-1.7.12.gemspec
  File: ‘/home/abod/.gem/specs/api.rubygems.org%443/quick/Marshal.4.8/bundler-1.7.12.gemspec’
  Size: 1025        Blocks: 8          IO Block: 1048576 regular file
Device: 2fh/47d Inode: 2285894     Links: 1
Access: (0644/-rw-r--r--)  Uid: (  730/    abod)   Gid: ( 1013/ wommack)
Access: 2015-02-03 01:12:35.573192019 -0500
Modify: 2015-02-02 13:53:41.227813208 -0500
Change: 2015-02-02 13:53:41.227813208 -0500
 Birth: -

$ fuser -m /home/abod/.gem/specs/api.rubygems.org%443/quick/Marshal.4.8/bundler-1.7.12.gemspec
/home/abod/.gem/specs/api.rubygems.org%443/quick/Marshal.4.8/bundler-1.7.12.gemspec: 57788c

有更多的进程正在访问该文件,但我将它们全部关闭后尝试重新安装,但我仍然收到了锁定错误。并且我的磁盘空间也没有用完。

以下是更多信息: 这是在计算机集群上。主目录/home/abod在/mnt某处建立了符号链接,并挂载到网络中的其他机器。

一些评论者要求输出挂载的结果。以下是有关主目录的行:

fileserver:/homes on /home type nfs (rw,noatime,nodiratime,vers=3,rsize=1048576,wsize=1048576,namlen=255,soft,nocto,noacl,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=128.175.xxx.xxx,mountvers=3,mountport=20048,mountproto=udp,local_lock=none,addr=128.175.xxx.xxx)
-hosts on /net/fileserver/homes type autofs (rw,relatime,fd=13,pgrp=1368,timeout=300,minproto=5,maxproto=5,offset)
fileserver:/homes on /net/fileserver/homes type nfs (rw,nosuid,nodev,relatime,vers=3,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=128.175.xxx.xxx,mountvers=3,mountport=20048,mountproto=udp,local_lock=none,addr=128.175.xxx.xxx)

编辑 我在rubygems的github页面上找到了一个与我的问题相关的票据:https://github.com/rubygems/rubygems/issues/1176


1
文件系统类型是什么(挂载的输出应包括此信息)? - Frederick Cheung
2个回答

3
注意:我正在提供悬赏以帮助原帖作者,因为我们需要更多专家的帮助。
以下是一些通用思路供您开始:
- 是否可能您已经超出了系统资源,例如磁盘空间? - 或者您的系统正在限制您可以使用的资源? - 或者尝试写入您没有权限或锁定守护程序的卷?
如果没有更好的答案,当您看到这篇文章时,您可以尝试运行这些命令,然后在您的问题中发布输出。
$ df

$ ulimit -a

$ uname -a

$ stat /home/abod/.gem/specs/api.rubygems.org%443/quick/Marshal.4.8/bundler-1.7.12.gemspec

$ fuser -m /home/abod/.gem/specs/api.rubygems.org%443/quick/Marshal.4.8/bundler-1.7.12.gemspec

如果您想终止访问该文件并可能持有锁定的任何进程:

$ fuser --kill /home/abod/.gem/specs/api.rubygems.org%443/quick/Marshal.4.8/bundler-1.7.12.gemspec

您可以通过运行以下命令来确定问题是由Ruby还是gem引起的:
path = "/home/abod/.gem/specs/api.rubygems.org%443/quick/Marshal.4.8/bundler-1.7.12.gemspec"
f = File.open(path, File::RDWR|File::CREAT, 0644){|f|
  f.flock(File::LOCK_EX)
  f.flock(File::LOCK_UN)
}

如果上面的代码失败,最可能的解释是您正在使用不支持文件锁定的文件系统。这与您的主目录被挂载到其他文件系统相一致,例如使用没有锁定守护进程的NFS。
编辑:OP写道:
引用: 运行您建议的代码: test.rb:4:in `flock': No locks available @ rb_file_flock - /home/abod/.gem/specs/api.rubygems.org%443/quick/Marshal.4.8/bundler-1.7.12.gems‌​pec (Errno::ENOLCK) from test.rb:4:in 块内'from test.rb:3:in `open' from test.rb:3:in' 看起来像是您的文件系统不提供锁定。
我有两个建议,并且我还在您的问题上添加了奖励以帮助吸引专家的注意。
  • If you have any filesystem space on that computer that isn't a mounted compute cluster, try installing a gem there. You can set the GEM_HOME environment variable like this:

    GEM_HOME=/foo/bar gem install <name>
    
  • If you can use a similar system, such as the same OS on VirtualBox or VMWare, then you can use the bundler gem, a Gemfile, and the command bundle pack. This creates a directory full of the gems listed in the Gemfile. You can then copy this directory anywhere you want, for example by using rsync, or scp, or sftp, etc. (This doesn't help much though with native gems, such as pg for PostgreSQL - you would need to be sure to install all the PostgresSQL dependencies and headers on your own).


运行您建议的代码:test.rb:4:in `flock': No locks available @ rb_file_flock - /home/abod/.gem/specs/api.rubygems.org%443/quick/Marshal.4.8/bundler-1.7.12.gemspec (Errno::ENOLCK) from test.rb:4:in `block in <main>' from test.rb:3:in `open' from test.rb:3:in `<main>' - Sandy
只是想澄清一下,当你说“类似的系统”时...我正在尝试在运行Fedora 19的集群上安装gems,所以如果我在本地机器(Mac OSX 10.6.8)上运行运行Fedora 19的虚拟机上的bundler,然后将其移动到集群上...这是你建议的要点吗? - Sandy

1

请向您的系统管理员请求卸载并挂载分区;NFS锁守护程序有时会出现问题,这样可以重置它。

(我知道这不是一个优雅或长期的解决方案)。


这个建议值得一试。我相信有些类型的远程挂载甚至不支持锁定。请发布 mount 命令的输出。 - Lencho Reyes

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接