Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

ThreadError: can't create Thread: Resource temporarily unavailable #4367

Closed
hendranata opened this issue Mar 14, 2016 · 34 comments
Closed

ThreadError: can't create Thread: Resource temporarily unavailable #4367

hendranata opened this issue Mar 14, 2016 · 34 comments

Comments

@hendranata
Copy link

I face a strange error.
but u can see my screenshot below

when i did "bundle"
it was showing an error
ThreadError: can't create Thread: Resource temporarily unavailable
http://s16.postimg.org/kyoo484gl/errorrrr.png

in this case, i suspect that the problem actually comming from memory, but I have check the free memory is around 2gb and swap 3gb..
but dont know why the error is still coming up.

anybody help me..
thanks

@RochesterinNYC
Copy link
Contributor

Please post your Gemfile and the results of bundle env (or post the full error report in this issue or a gist or something).

@hendranata
Copy link
Author

## here is my Gemfile

source 'https://rubygems.org'

gem 'rails', '4.2.5.1'
gem 'bootstrap-sass', '~> 3.3', '>= 3.3.6'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc

group :development, :test do
  gem 'byebug'
end

group :development do
  gem 'web-console', '~> 2.0'
  gem 'sqlite3'
  gem 'spring'
end

group :production do
#  gem 'pg',             '0.17.1'
#  gem 'rails_12factor', '0.0.2'
 # gem 'puma',           '3.1.0'
end

## and here is result of bundle env

`(app:2.1)plncikande@iix-ssd [~/app]# bundle env
Environment

Bundler   1.12.0.rc
Rubygems  2.2.5
Ruby      2.1.8p440 (2015-12-16 revision 53160) [i686-linux-gnu]
GEM_HOME  /home/plncikande/rubyvenv/app/2.1
GEM_PATH  /home/plncikande/rubyvenv/app/2.1:/opt/alt/ruby21/lib/ruby/gems/2.1.0
Git       not installed

Bundler settings

orig_path
  Set via BUNDLE_ORIG_PATH: "/home/plncikande/rubyvenv/app/2.1/bin:/opt/alt/ruby21/bin:/usr/local/jdk/bin:/home/plncikande/perl5/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11R6/bin:/home/plncikande/bin"
orig_gem_path
  Set via BUNDLE_ORIG_GEM_PATH: "/home/plncikande/rubyvenv/app/2.1:/opt/alt/ruby21/lib/ruby/gems/2.1.0"

Gemfile

source 'https://rubygems.org'

gem 'rails', '4.2.5.1'
gem 'bootstrap-sass', '~> 3.3', '>= 3.3.6'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc

group :development, :test do
  gem 'byebug'
end

group :development do
  gem 'web-console', '~> 2.0'
  gem 'sqlite3'
  gem 'spring'
end

group :production do
#  gem 'pg',             '0.17.1'
#  gem 'rails_12factor', '0.0.2'
 # gem 'puma',           '3.1.0'
end

Gemfile.lock

<No /home/plncikande/app/Gemfile.lock found>`

## and here is the error message when I type "bundle install"

(app:2.1)plncikande@iix-ssd [~/app]# bundle
Fetching gem metadata from https://rubygems.org/Retrying fetcher due to error (2/4): ThreadError can't create Thread: Resource temporarily unavailable
Retrying fetcher due to error (3/4): ThreadError can't create Thread: Resource temporarily unavailable
Retrying fetcher due to error (4/4): ThreadError can't create Thread: Resource temporarily unavailable
--- ERROR REPORT TEMPLATE -------------------------------------------------------
- What did you do?

  I ran the command `/home/plncikande/rubyvenv/app/2.1/bin/bundle `

- What did you expect to happen?

  I expected Bundler to...

- What happened instead?

  Instead, what actually happened was...


Error details

    ThreadError: can't create Thread: Resource temporarily unavailable
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/worker.rb:29:in `start'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/worker.rb:29:in `block in initialize'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/worker.rb:28:in `initialize'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/worker.rb:28:in `new'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/worker.rb:28:in `initialize'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/fetcher/compact_index.rb:85:in `new'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/fetcher/compact_index.rb:85:in `block (2 levels) in compact_index_client'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/vendor/compact_index_client/lib/compact_index_client.rb:41:in `call'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/vendor/compact_index_client/lib/compact_index_client.rb:41:in `dependencies'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/fetcher/compact_index.rb:41:in `specs_for_names'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/fetcher/compact_index.rb:29:in `specs'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/fetcher/compact_index.rb:15:in `call'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/fetcher/compact_index.rb:15:in `block in compact_index_request'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/fetcher.rb:125:in `block in specs'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/fetcher.rb:124:in `each'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/fetcher.rb:124:in `specs'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/fetcher.rb:109:in `block in specs_with_retry'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/retry.rb:39:in `call'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/retry.rb:39:in `run'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/retry.rb:29:in `attempt'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/fetcher.rb:108:in `specs_with_retry'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/source/rubygems.rb:354:in `block (2 levels) in remote_specs'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/source/rubygems.rb:352:in `each'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/source/rubygems.rb:352:in `block in remote_specs'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/index.rb:10:in `build'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/source/rubygems.rb:335:in `remote_specs'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/source/rubygems.rb:82:in `specs'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/definition.rb:211:in `block (2 levels) in index'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/definition.rb:209:in `each'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/definition.rb:209:in `block in index'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/index.rb:10:in `build'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/definition.rb:206:in `index'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/definition.rb:200:in `resolve'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/definition.rb:140:in `specs'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/definition.rb:129:in `resolve_remotely!'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/installer.rb:195:in `resolve_if_need'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/installer.rb:70:in `run'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/installer.rb:22:in `install'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/cli/install.rb:102:in `run'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/cli.rb:175:in `install'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/cli.rb:11:in `start'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/exe/bundle:27:in `block in <top (required)>'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/lib/bundler/friendly_errors.rb:98:in `with_friendly_errors'
      /home/plncikande/rubyvenv/app/2.1/gems/bundler-1.12.0.rc/exe/bundle:19:in `<top (required)>'
      /home/plncikande/rubyvenv/app/2.1/bin/bundle:23:in `load'
      /home/plncikande/rubyvenv/app/2.1/bin/bundle:23:in `<main>'

Environment

  Bundler   1.12.0.rc
  Rubygems  2.2.5
  Ruby      2.1.8p440 (2015-12-16 revision 53160) [i686-linux-gnu]
  GEM_HOME  /home/plncikande/rubyvenv/app/2.1
  GEM_PATH  /home/plncikande/rubyvenv/app/2.1:/opt/alt/ruby21/lib/ruby/gems/2.1.0
  Git       not installed

      Bundler settings

  orig_path
    Set via BUNDLE_ORIG_PATH: "/home/plncikande/rubyvenv/app/2.1/bin:/opt/alt/ruby21/bin:/usr/local/jdk/bin:/home/plncikande/perl5/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11R6/bin:/home/plncikande/bin"
  orig_gem_path
    Set via BUNDLE_ORIG_GEM_PATH: "/home/plncikande/rubyvenv/app/2.1:/opt/alt/ruby21/lib/ruby/gems/2.1.0"
--- TEMPLATE END ----------------------------------------------------------------

Unfortunately, an unexpected error occurred, and Bundler cannot continue.

First, try this link to see if there are any existing issue reports for this error:
https://github.com/bundler/bundler/search?q=can%27t+create+Thread%3A+Resource+temporarily+unavailable&type=Issues

If there aren't any reports for this error yet, please create copy and paste the report template above into a new issue. Don't forget to anonymize any private data! The new issue form is located at:
https://github.com/bundler/bundler/issues/new

@RochesterinNYC
Copy link
Contributor

Haven't been able to reproduce this on Linux or a Mac machine yet.

Could you try updating rubygems to the latest stable and seeing if that affects anything?

@sstern6
Copy link

sstern6 commented Mar 29, 2016

@RochesterinNYC && @hendranata I have been doing some reading in other issues that reference the ThreadError. In addition, @RochesterinNYC was not able to reproduce locally, what I'm thinking is that it might not be a bundler issue. In the other issues there was an infinite loop or a re-initialization within an iteration in the developers codebase. I have attached the issues I am basing my conclusion off below.

berkshelf/ridley#312

ruby-amqp/bunny#315

@omninonsense
Copy link

omninonsense commented Apr 18, 2016

I can confirm/reproduce this error. I upgraded to 1.12.0.rc.2 due to #4182. This does not happen on 1.11.0 or 1.10.6. If it's of any relevance, this is a CloudLinux server. This is happening on a freshly-created Rails project (created with Rails 4.2.1) with rails new datappname -d mysql.

Edit: Tried it with Rails 4.2.6 today, and the same thing happened.

$ bundle install --path vendor/bundle
Fetching gem metadata from https://rubygems.org/Retrying fetcher due to error (2/4): ThreadError can't create Thread: Resource temporarily unavailable
Retrying fetcher due to error (3/4): ThreadError can't create Thread: Resource temporarily unavailable
Retrying fetcher due to error (4/4): ThreadError can't create Thread: Resource temporarily unavailable
^C
/usr/local/ruby2/lib/ruby/gems/2.2.0/gems/bundler-1.12.0.rc.2/lib/bundler/source/git/git_proxy.rb:149:in ``': Resource temporarily unavailable - git (Errno::EAGAIN)
    from /usr/local/ruby2/lib/ruby/gems/2.2.0/gems/bundler-1.12.0.rc.2/lib/bundler/source/git/git_proxy.rb:149:in `block in git'
    from /usr/local/ruby2/lib/ruby/gems/2.2.0/gems/bundler-1.12.0.rc.2/lib/bundler/shared_helpers.rb:72:in `call'
    from /usr/local/ruby2/lib/ruby/gems/2.2.0/gems/bundler-1.12.0.rc.2/lib/bundler/shared_helpers.rb:72:in `with_clean_git_env'
    from /usr/local/ruby2/lib/ruby/gems/2.2.0/gems/bundler-1.12.0.rc.2/lib/bundler/source/git/git_proxy.rb:149:in `git'
    from /usr/local/ruby2/lib/ruby/gems/2.2.0/gems/bundler-1.12.0.rc.2/lib/bundler/source/git/git_proxy.rb:83:in `version'
    from /usr/local/ruby2/lib/ruby/gems/2.2.0/gems/bundler-1.12.0.rc.2/lib/bundler/env.rb:78:in `git_version'
    from /usr/local/ruby2/lib/ruby/gems/2.2.0/gems/bundler-1.12.0.rc.2/lib/bundler/env.rb:22:in `report'
    from /usr/local/ruby2/lib/ruby/gems/2.2.0/gems/bundler-1.12.0.rc.2/lib/bundler/friendly_errors.rb:74:in `request_issue_report_for'
    from /usr/local/ruby2/lib/ruby/gems/2.2.0/gems/bundler-1.12.0.rc.2/lib/bundler/friendly_errors.rb:40:in `log_error'
    from /usr/local/ruby2/lib/ruby/gems/2.2.0/gems/bundler-1.12.0.rc.2/lib/bundler/friendly_errors.rb:100:in `rescue in with_friendly_errors'
    from /usr/local/ruby2/lib/ruby/gems/2.2.0/gems/bundler-1.12.0.rc.2/lib/bundler/friendly_errors.rb:98:in `with_friendly_errors'
    from /usr/local/ruby2/lib/ruby/gems/2.2.0/gems/bundler-1.12.0.rc.2/exe/bundle:19:in `<top (required)>'
    from /usr/local/ruby2/bin/bundle:22:in `load'
    from /usr/local/ruby2/bin/bundle:22:in `<main>

@hendranata
Copy link
Author

@omninonsense yes my problem actually occur when using cloudlinux server. and after create a support ticket to them, they had solved the problem in the easy way..quite easy. in this case my server is running under cpanel /whm and go to LVM manager, increase the Physical memory for each user and also change the other settings like PMEM, NPROC & EP..
viola now bundle is working find.. :)

@omninonsense
Copy link

@hendranata Ah, thanks for pointing that out. If I remember correctly, the user in question didn't have these limits, however I will double check. I suppose this isn't really a Bundler issue in itself, though.

@domcleal
Copy link
Contributor

domcleal commented Apr 29, 2016

in this case my server is running under cpanel /whm and go to LVM manager, increase the Physical memory for each user and also change the other settings like PMEM, NPROC & EP..

nproc limits are also very common on EL6/7, which defaults to a 1k soft limit for non-root users. This can be easily changed in /etc/security/limits.d/90-nproc.conf, or by removing the file. Our CI environment quickly hit this limit with Bundler 1.12.0 when running a few jobs in parallel.

Edit: correction, EL6 has a 1k limit and EL7 has a 4k limit by default. EL7's config file is 20-nproc.conf.

@naox
Copy link

naox commented Apr 30, 2016

Bundler 1.12.1 - I can confirm that this bug is real and is still present. In 1.11.2 bug is not present
Bug occurs when shell user has nproc limit in /etc/security/limits.conf (centos,redhat os) that is below 330 (in my test case) To observe bug put in /etc/security/limits.conf

username hard nproc 70

relogin into shell and then run bundle install

Fetching gem metadata from https://rubygems.org/Retrying fetcher due to error (2/4): ThreadError can't create Thread: Resource temporarily unavailable
Retrying fetcher due to error (3/4): ThreadError can't create Thread: Resource temporarily unavailable
Retrying fetcher due to error (4/4): ThreadError can't create Thread: Resource temporarily unavailable

bundler really should not hit such high limit as 70 nproc. Removing such limits leaves system open for fork bomb attacks. Please make bundler use not more that 4 nproc.

--jobs 1 does not make bug go away. Even if it did that switch is not enough and there would be a need to take this parameter from ENV variable - to allow defining a default value by sysadmin.

@segiddins
Copy link
Member

@ghost
Copy link

ghost commented May 2, 2016

If you're running cPanel on the Cloudlinux server, disable shell form bomb protection in cPanel

@nemhods
Copy link

nemhods commented May 2, 2016

I can confirm this issue in another hosted environment. Numproc limits seem to be prominent on lower-end virtual rootservers. My limit (I'd need to upgrade my package to raise it) is at 320 processes, and the system idles at around 80 processes. During an installation of OpenProject, bundle install hits the limit, meaning it tries to utilize more than 240 processes/threads.

This seems to be a really high number. Is it possible that this problem is rooted somewhere else, maybe the use of rbenv, older ruby versions etc?

@will-in-wi
Copy link
Contributor

I'll throw in another confirmation. Doesn't happen on my Mac, but when I tried to deploy (using Capistrano) to Webfaction shared hosting I get the aformentioned error. gem uninstall bundler && gem install bundler -v '< 1.12' allowed me to deploy.

Thanks for your work on this!

@will-in-wi
Copy link
Contributor

Ruby 2.3.1, installed using rbenv, if that helps.

@JasonBarnabe
Copy link

I can also confirm that downgrading to 1.11.2 "fixes" the issue.

Low and even draconian limits on resources are very common in VMs and shared hosting. Of all the things I run in my VM, bundler should not be the thing that pushes the limits :)

@segiddins
Copy link
Member

A PR improving this would be greatly appreciated :)

@RochesterinNYC
Copy link
Contributor

Aside from a PR fixing this, a Docker image or run container configuration, vagrant box, or other way to reproduce this issue with minimal dependencies/reliance on external cloud services or etc. would be great!

@will-in-wi
Copy link
Contributor

https://github.com/will-in-wi/bundler-bug-reproduction

This Vagrant configuration uses the real-world limits.conf from my WebFaction host. Instructions to reproduce in the readme.

@caporaldjon
Copy link

On my Bluehost hosting, I had this problem. doing gem uninstall bundler && gem install bundler -v '< 1.12' corrected the problem.

@chaoticbear
Copy link

Confirmed this is broken on my OpenSuse tumbleweed desktop OS. Not a VM.
Using bundler-1.12.1

gem uninstall bundler && gem install bundler -v '< 1.12' fixed it for me.

@colby-swandale
Copy link
Member

colby-swandale commented May 24, 2016

i have been able to successfully reproduce this in Vagrant thanks to @will-in-wi.

Looking into https://github.com/bundler/bundler/blob/7ae072865e3fc23d9844322dde6ad0f6906e3f2c/lib/bundler/worker.rb it's obvious that we're not closing the threads (though i have not figured out if we can/should). As a consequence this is causing limits.conf to prevent ruby from creating any more [threads]. Maybe we can make this more resourceful? something i would like to look into.

Here is an example bundle install where i'm printing the number of threads on #initialize in worker.rb.

Fetching gem metadata from https://rubygems.org/"
Thread count: 1"
"Thread count: 26"
"Thread count: 51"
"Thread count: 76"
"Thread count: 101"
"Thread count: 126"
"Thread count: 151"
"Thread count: 176"
"Thread count: 201"
"Thread count: 226"

Fetching version metadata from https://rubygems.org/
"Thread count: 251"
"Thread count: 276"
Retrying fetcher due to error (2/4): ThreadError can't create Thread: Resource temporarily unavailable
"Thread count: 295"
Retrying fetcher due to error (3/4): ThreadError can't create Thread: Resource temporarily unavailable
"Thread count: 295"
Retrying fetcher due to error (4/4): ThreadError can't create Thread: Resource temporarily unavailable
"Thread count: 295"

and my limits.conf file

* hard nproc 300

@will-in-wi
Copy link
Contributor

Heh, @colby-swandale I was doing the same thing at the same time.

#4607 is a PR which should fix the issue. Could you test?

Thanks all!

@colby-swandale
Copy link
Member

@will-in-wi awesome work!

This is looking much better 😃

Fetching gem metadata from https://rubygems.org/
"Thread count: 1"
"Thread count: 1"
"Thread count: 1"
"Thread count: 1"
"Thread count: 1"
"Thread count: 1"
"Thread count: 1"
"Thread count: 1"
"Thread count: 1"
"Thread count: 1"

Fetching version metadata from https://rubygems.org/"1"
"Thread count: 1"

Fetching dependency metadata from https://rubygems.org/"1"

"Thread count: 1"
Installing rake 11.1.2
Installing i18n 0.7.0
Using json 1.8.3
Installing minitest 5.9.0
Installing thread_safe 0.3.5
Installing builder 3.2.2
Installing erubis 2.7.0
Installing mini_portile2 2.0.0
Installing rack 1.6.4
Installing mime-types-data 3.2016.0521
Installing arel 6.0.3
Installing concurrent-ruby 1.0.2
Using bundler 1.12.3
Installing thor 0.19.1
Installing tzinfo 1.2.2
Installing nokogiri 1.6.7.2 with native extensions
Installing rack-test 0.6.3
Installing mime-types 3.1
Installing sprockets 3.6.0
Installing activesupport 4.2.6
Installing loofah 2.0.3
Installing mail 2.6.4
Installing rails-deprecated_sanitizer 1.0.3
Installing globalid 0.3.6
Installing activemodel 4.2.6
Installing rails-html-sanitizer 1.0.3
Installing rails-dom-testing 1.0.7
Installing activejob 4.2.6
Installing activerecord 4.2.6
Installing actionview 4.2.6
Installing actionpack 4.2.6
Installing actionmailer 4.2.6
Installing railties 4.2.6
Installing sprockets-rails 3.0.4
Installing rails 4.2.6
Bundle complete! 1 Gemfile dependency, 35 gems now installed.
Bundled gems are installed into ./vendor.
"Final Thread count: 1"

@shoerofi
Copy link

@joshfleming you save my day :D

homu added a commit that referenced this issue May 25, 2016
Clean up worker threads once done with them

Right now, the thread pools created by CompactIndex are not cleaned up once they are done. I assume that over time, they would be garbage collected, but in the meantime there could be 200+ threads running. Many shared hosts have fork bomb protection set up which kills Bundler.

This patch will clean up the threads as soon as they are done, keeping the total number of active threads at any one time to a minimum.

Fixes #4367
segiddins pushed a commit that referenced this issue May 25, 2016
Clean up worker threads once done with them

Right now, the thread pools created by CompactIndex are not cleaned up once they are done. I assume that over time, they would be garbage collected, but in the meantime there could be 200+ threads running. Many shared hosts have fork bomb protection set up which kills Bundler.

This patch will clean up the threads as soon as they are done, keeping the total number of active threads at any one time to a minimum.

Fixes #4367
@indirect
Copy link
Member

The fix was just released in Bundler 1.12.5, so you can use it by running gem install bundler.

@stalker37
Copy link

on rvm and ruby 2.2.4 and bundler-1.13.1 problem is alive. debian jessie

@segiddins
Copy link
Member

@stalker37 please open a new issue

@azamouchi
Copy link

This is my enviroment, and i'm facing the same problem mentioned above on "Debian GNU/Linux 8 (jessie)"

Bundler 1.13.7
Rubygems 2.2.2
Ruby 2.1.5p273 (2014-11-13 revision 0) [x86_64-linux-gnu]

$bundle install --without development test

Fetching gem metadata from https://rubygems.org/.
Retrying fetcher due to error (2/4): ThreadError can't create Thread: Resource temporarily unavailable.
Retrying fetcher due to error (3/4): ThreadError can't create Thread: Resource temporarily unavailable.
Retrying fetcher due to error (4/4): ThreadError can't create Thread: Resource temporarily unavailable./var/lib/gems/2.1.0/gems/bundler-1.13.7/lib/bundler/source/git/git_proxy.rb:161:in ``': Cannot allocate memory - git (Errno::ENOMEM)
	from /var/lib/gems/2.1.0/gems/bundler-1.13.7/lib/bundler/source/git/git_proxy.rb:161:in `block (2 levels) in git'
	from /var/lib/gems/2.1.0/gems/bundler-1.13.7/lib/bundler/source/git/git_proxy.rb:233:in `block in capture_and_filter_stderr'
	from /usr/lib/ruby/2.1.0/tempfile.rb:324:in `open'
	from /var/lib/gems/2.1.0/gems/bundler-1.13.7/lib/bundler/source/git/git_proxy.rb:231:in `capture_and_filter_stderr'
	from /var/lib/gems/2.1.0/gems/bundler-1.13.7/lib/bundler/source/git/git_proxy.rb:161:in `block in git'
	from /var/lib/gems/2.1.0/gems/bundler-1.13.7/lib/bundler/shared_helpers.rb:72:in `call'
	from /var/lib/gems/2.1.0/gems/bundler-1.13.7/lib/bundler/shared_helpers.rb:72:in `with_clean_git_env'
	from /var/lib/gems/2.1.0/gems/bundler-1.13.7/lib/bundler/source/git/git_proxy.rb:160:in `git'
	from /var/lib/gems/2.1.0/gems/bundler-1.13.7/lib/bundler/source/git/git_proxy.rb:88:in `full_version'
	from /var/lib/gems/2.1.0/gems/bundler-1.13.7/lib/bundler/env.rb:78:in `git_version'
	from /var/lib/gems/2.1.0/gems/bundler-1.13.7/lib/bundler/env.rb:22:in `report'
	from /var/lib/gems/2.1.0/gems/bundler-1.13.7/lib/bundler/friendly_errors.rb:74:in `request_issue_report_for'
	from /var/lib/gems/2.1.0/gems/bundler-1.13.7/lib/bundler/friendly_errors.rb:40:in `log_error'
	from /var/lib/gems/2.1.0/gems/bundler-1.13.7/lib/bundler/friendly_errors.rb:102:in `rescue in with_friendly_errors'
	from /var/lib/gems/2.1.0/gems/bundler-1.13.7/lib/bundler/friendly_errors.rb:100:in `with_friendly_errors'
	from /var/lib/gems/2.1.0/gems/bundler-1.13.7/exe/bundle:26:in `<top (required)>'
	from /usr/local/bin/bundle:23:in `load'
	from /usr/local/bin/bundle:23:in `<main>' ```

@will-in-wi
Copy link
Contributor

@azamouchi: Could you post /etc/security/limits.conf and the amount of memory from the server in question?

@azamouchi
Copy link

@will-in-wi

Amount of memory : i'm surprised to see 0kB free memory ! do you think that this could be the problem ?

root@vps36195:~# cat  /proc/meminfo
MemTotal:        2097152 kB
MemFree:               0 kB
Cached:           843792 kB
Buffers:               0 kB
Active:          1109584 kB
Inactive:         652748 kB
Active(anon):     539908 kB
Inactive(anon):   378632 kB
Active(file):     569676 kB
Inactive(file):   274116 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       2097152 kB
SwapFree:        1817868 kB
Dirty:                12 kB
Writeback:             0 kB
AnonPages:        918540 kB
Shmem:            975604 kB
Slab:              96140 kB
SReclaimable:      43892 kB
SUnreclaim:        52248 kB

And the /etc/security/limits.conf content

# /etc/security/limits.conf
#
#Each line describes a limit for a user in the form:
#
#<domain>        <type>  <item>  <value>
#
#Where:
#<domain> can be:
#        - a user name
#        - a group name, with @group syntax
#        - the wildcard *, for default entry
#        - the wildcard %, can be also used with %group syntax,
#                 for maxlogin limit
#        - NOTE: group and wildcard limits are not applied to root.
#          To apply a limit to the root user, <domain> must be
#          the literal username root.
#
#<type> can have the two values:
#        - "soft" for enforcing the soft limits
#        - "hard" for enforcing hard limits
#
#<item> can be one of the following:
#        - core - limits the core file size (KB)
#        - data - max data size (KB)
#        - fsize - maximum filesize (KB)
#        - memlock - max locked-in-memory address space (KB)
#        - nofile - max number of open files
#        - rss - max resident set size (KB)
#        - stack - max stack size (KB)
#        - cpu - max CPU time (MIN)
#        - nproc - max number of processes
#        - as - address space limit (KB)
#        - maxlogins - max number of logins for this user
#        - maxsyslogins - max number of logins on the system
#        - priority - the priority to run user process with
#        - locks - max number of file locks the user can hold
#        - sigpending - max number of pending signals
#        - msgqueue - max memory used by POSIX message queues (bytes)
#        - nice - max nice priority allowed to raise to values: [-20, 19]
#        - rtprio - max realtime priority
#        - chroot - change root to directory (Debian-specific)
#
#<domain>      <type>  <item>         <value>
#

#*               soft    core            0
#root            hard    core            100000
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#ftp             -       chroot          /ftp
#@student        -       maxlogins       4

# End of file

@will-in-wi
Copy link
Contributor

Yeah, that'd be my first guess. Something on your system is taking up all of your memory, and leaving none for Bundler to run. There is only 2G of total memory, which is somewhat small for a lot of use cases.

You can use Top or PS to find out what is using all of the memory.

@azamouchi
Copy link

@will-in-wi Ok, i'll check that. Thank you for your help 👍

@azamouchi
Copy link

@will-in-wi using top i can see that i have zero free ram memory, but there is a 2Go of swap memory that can be used in case of need, do you mean that even this 2Go memory is not enough to install the bundle ? i know that swap memory is slower, but at least it can handle the install process no ?

top - 21:44:33 up  2:03,  1 user,  load average: 0,07, 0,05, 0,01
Tasks:  89 total,   1 running,  88 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0,0 us,  0,0 sy,  0,0 ni,100,0 id,  0,0 wa,  0,0 hi,  0,0 si,  0,0 st
KiB Mem:   2097152 total,  2097152 used,        0 free,        0 buffers
KiB Swap:  2097152 total,        0 used,  2097152 free.   621576 cached Mem

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND                                                                                              
 7413 root      30  10  686564  11024   3196 S  0,3  0,5   0:07.15 fail2ban-server                                                                                      
    1 root      30  10   28688   3748   1964 S  0,0  0,2   0:00.37 systemd                                                                                              
    2 root      30  10       0      0      0 S  0,0  0,0   0:00.00 kthreadd/36195                                                                                       
    3 root      30  10       0      0      0 S  0,0  0,0   0:00.00 khelper/36195                                                                                        
   53 root      30  10   38864   1632   1176 S  0,0  0,1   0:00.00 systemd-udevd                                                                                        
   85 root      30  10   32912   3632   3340 S  0,0  0,2   0:00.45 systemd-journal                                                                                      
  237 root      30  10   10544    708    584 S  0,0  0,0   0:00.00 inetd                                                                                                
  238 root      30  10  204612  18404  15136 S  0,0  0,9   0:00.12 php-fpm                                                                                              
  239 root      30  10  205076  18632  15232 S  0,0  0,9   0:00.13 php-fpm                                                                                              
  240 clamav    30  10   97600  10508   7376 S  0,0  0,5   0:07.83 freshclam                                                                                            
  241 root      30  10   55128   3124   2452 S  0,0  0,1   0:00.03 sshd                                                                                                 
  248 root      30  10   28212   1628   1324 S  0,0  0,1   0:00.02 systemd-logind                                                                                       

@will-in-wi
Copy link
Contributor

This gets deeper into memory management in Linux than I am knowledgeable about. TL;DR: I don't know. But I'll give my guess for you to have a hopefully better place to start from.

My basic understanding is that swap is used such that when memory gets low, memory pages are sent to the swap storage based on which pages are Least Recently Used. In this case, I would expect then that for the purposes of Bundler, you have the full 4G of memory available, albeit getting super slow.

However, if the issue is related to this ticket, then it would be increased memory usage due to forking. When a process forks, the heap is shared, but the stack is duplicated. I'm not sure whether between Ruby and Linux, this happens using a Copy on Write mechanism which would minimise memory usage, or just a full copy, which would potentially increase memory usage. I'm really fuzzy here, so please verify what I'm saying.

It is possible that Bundler is using more than 2G of memory during a run. You might want to run it, and watch top while it runs.

Another piece of this is that I'm not sure memory is the only way ThreadError can't create Thread: Resource temporarily unavailable can happen. You might want to search for other possible root causes and investigate them.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests