-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Bundler.with_clean_env and vendorized gems #1981
Comments
Yes. That is the entire point of with_clean_env. If you want to use gems from a path, she'll out directly: On Jun 12, 2012, at 9:05 PM, Seth Vargoreply@reply.github.com wrote:
|
Not if I'm trying to run something like |
What do you mean by "Bundler will complain that the specs have already been loaded"? |
For what it's worth, it isn't currently supported to run |
($) represents the shell command run inside the class above: Dirty environment
Clean environment
What's worth noting also: if I shell out twice, in a "dirty" environment, the first will fail, but the second will succeed:
|
Very similar: #1569 |
@hone, any idea why the specs would already be loaded the first time a subshell bundler is invoked? |
It looks like this used to work in 1.0.0 |
Well, fwiw, 1.0.0 has known bugs in with_clean_env that mean it doesn't clean the env. So that may be what you're seeing. On Jun 14, 2012, at 6:40 AM, Seth Vargoreply@reply.github.com wrote:
|
But the bug exists in |
You should be able to shell out from inside |
Is this still an issue? Do we have a simple way to reproduce it? |
I no longer have the project this was occurring in. We moved off appraisal and no longer saw the issue. |
I've encountered something similar. I have two apps installed with "bundle install --deployment", and AppA needs to call a script in AppB. When AppA shells out inside Bundler.with_clean_env to call "bundle exec AppB/bin/script", I get the following error:
/opt/ruby-enterprise/bin/gem -v is 1.8.15. |
@sdrye, I suggest something like this:
|
Changing the command line to place the environment variables onto the bundle exec command line (instead of using the original "export BUNDLE_GEMFILE && bundle exec /opt/AppB/bin/script") also fails.
was what we had originally. That failed, it could not find the bundler gem and in addition it used the wrong Gemfile (this was clear from the "amongst" array, which contained the gems from AppA) . Switching to
picked up the right gemfile (the contents of the "amongst" list matched the Gemfile for AppB this time), but again complains that "Could not find bundler (>= 0) amongst [...]", the exception trace that's in the report above. Using
inside the Dir.chdir gets the same error. On irc this morning I got the suggestion to try adding bash -c, that failed as well, in the same way. |
That is extremely strange. The most likely option is that you're nesting shells in such a way that Bundler no longer has access to the original, un-bundled ENV variables. If you shell out to something that shells out to bundler, for example, that could happen. |
Our "AppA" is a straightforward Rails 2.3.18 app, so it shouldn't be doing anything strange (other than being 2.3.x). That said, I've written two little command line apps to try to reproduce the issue and can't. I'll keep trying to come up with a reproducible test case. |
Yeah... That also makes me suspect that this is a double-shellout case. Is it possible that your production servers are getting launched by code that has a loaded bundle? If they inherit the env from a parent process, that might do it. with_clean_env will only be able to restore one level of env up from where it is run. On Mon, Jul 15, 2013 at 8:21 AM, sdrye notifications@github.com wrote:
|
Have you heard of anyone having issues using bundler with thin? I've narrowed it down to the point where if I run "bundle exec script/server thin -e production" it works, but if I run "bundle exec thin start -d --config=/etc/thin/AppA" it fails. |
@sdrye just jumpin in because this one looks familiar. There are known issues with bundler not passing all the config flags. You could try surrounding it with quotes: $ bundle exec 'thin start -d --config=/...' |
No joy with the quotes, unfortunately. It appears to be an issue when thin creates multiple servers. So "bundle exec thin start -e production" works, but "bundle exec thin start -e production -s 4" doesn't. |
Doesn't seem to be related to how thin daemonizes the app, either. "bundle exec thin start -e production -p 3000 -d --pid tmp/pids/thin.3000.pid" plus "bundle exec thin start -e production -p 3001 -d --pid tmp/pids/thin.3001.pid" gives me two servers both of which work. So it's very specific to thin starting multiple servers by itself. |
I don't have any experience with how thin starts multiple servers, but I haven't seen any previous reports of Bundler interfering with either forking or threading servers (like Puma, or Unicorn, Phusion Passenger). You could try executing thin without using the |
I've found the cause. It's in the way that thin's "cluster" mode starts servers. It's what you thought it might be, @indirect, a double-shellout. When you start thin with servers: or --servers, it goes through https://github.com/macournoyer/thin/blob/v1.5.1/lib/thin/controllers/cluster.rb Which then calls "run" in https://github.com/macournoyer/thin/blob/v1.5.1/lib/thin/command.rb In this second one you can see that it uses "shellify" to create a new command line for launching the child server and calls popen3 rather than just forking. The command line it creates is just a straight call to "thin", without bundle exec. So the outer, initial process is called with "bundle exec thin start", but then it starts the children with just "thin start". So it looks like with_clean_env can't work correctly with thin in cluster mode (at least at 1.5.1, not sure yet about 2.0.0-pre) because of how thin implemented cluster mode. Unfortunately cluster mode is what thin does when you set it up in a production config with a config file in /etc/thin. At least there's a workaround, though, where you can start each of the servers individually with --port --pid and --log. |
Ahh, that makes sense. That also likely explains why I haven't seen this reported before, since everyone I've talked to who uses thin manages multiple processes without using thin's cluster mode. Thanks for tracking it down! If you really want to use thins's cluster mode, you can probably work around it by writing a script that does the same thing as thin, but uses with_clean_env around the open3. On Wed, Jul 17, 2013 at 6:49 AM, sdrye notifications@github.com wrote:
|
Overview
When shelling out with a bundler subshell, bundler cannot find vendorized gems.
Example
This will throw an error saying
dependency ... to_specs Could not find gem bundler amongst [...]
The text was updated successfully, but these errors were encountered: