Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with concurrent bundle installs with shared gem cache #3191

Closed
stefansedich opened this issue Jul 8, 2017 · 10 comments
Closed

Issues with concurrent bundle installs with shared gem cache #3191

stefansedich opened this issue Jul 8, 2017 · 10 comments

Comments

@stefansedich
Copy link

I am attempting to use a shared gem cache with a docker-compose setup, a sample project is available here: https://github.com/stefansedich/bundle-test which easily replicates the issue by simply running run.sh.

The error is consistent and one of the two containers will fail to compile the native extensions for in this case the pg gem I assume due to the concurrent installs attempting to create the Makefile.

What is the best way to handle this scenario, my current solution is to wrap my bundle install in a script that will use flock to limit concurrent installs.

@indirect
Copy link
Member

indirect commented Jul 8, 2017

@stefansedich thank you for reporting this!

@segiddins ugh this scenario did not even occur to me 😭 I'm thinking process lock file a la git?

@stefansedich
Copy link
Author

FYI my current solution using a install wrapper script does the trick!

#!/bin/bash

set -e

(
  flock 200

  bundle install
) 200>/.gems/install.lock

@stefansedich
Copy link
Author

@indirect if a process lock is the desired solution and everyone is happy with that I am happy to tackle it and submit a PR for it.

@indirect
Copy link
Member

indirect commented Jul 8, 2017

@stefansedich I think that's the way to go for now—we're not designed to allow multiple concurrent processes. Maybe a future goal can be optimizing that beyond a process lock.

@stefansedich
Copy link
Author

Sounds good, from my initial look it looks like Installer#run is the best place to put the lock, does that sound right to you?

@indirect
Copy link
Member

indirect commented Jul 8, 2017

That sounds right to me. You'll also want to check the update command and make sure it shares the lock. 👍🏻

@segiddins
Copy link
Member

We could also do everything in temporary directories and move stuff since moves are atomic

@stefansedich
Copy link
Author

@segiddins does it make more sense to just wait? otherwise in this example I compile PG twice in parallel, if we just lock and wait by the time the second install can continue PG should already be compiled and ready to use?

@segiddins
Copy link
Member

You've given the install command twice, so I don't think that installing twice is out of the question. In addition, in my experience proper multi-process coordination is a lot harder than just sticking with atomic ops

bundlerbot referenced this issue in rubygems/bundler Jul 15, 2017
Adding process lock for bundle install operations

### What was the end-user problem that led to this PR?

As per #5851 multiple concurrent bundle installs would cause failures when compiling

### What was your diagnosis of the problem?

As described in #5851 a sample project was created demonstrating the issue when running a docker-compose solution of 2 containers using a gem cache volume

### What is your fix for the problem, implemented in this PR?

The fix is to implement an installation process lock so that only one process can execute an install at one time

### Why did you choose this fix out of the possible options?

I chose this fix because it was discussed in #5851 as a possible solution
@hsbt hsbt transferred this issue from rubygems/bundler Mar 14, 2020
@deivid-rodriguez
Copy link
Member

This was apparently fixed by rubygems/bundler#5852, but never closed.

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

No branches or pull requests

6 participants