Skip to content

Commit 168266e

Browse files
hsbtclaude
andcommitted
Load vendored persistent before activating Artifice in-process
Artifice replaces Gem::Net::HTTP, so when bundler/vendored_persistent gets lazily required while Artifice is active, the vendored Persistent classes are defined under the Artifice replacement. After deactivation Gem::Net::HTTP::Persistent becomes unresolvable, and the vendored connection_pool fork hook then raises NameError on any later Process.fork in the same rspec worker, failing worker_spec whenever it shares a process with parallel_installer_spec. Load it up front like gem_remote_fetcher_spec already does, before requiring support/artifice/compact_index, which activates Artifice on load. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent ae0296a commit 168266e

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

spec/bundler/installer/parallel_installer_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
RSpec.describe Bundler::ParallelInstaller do
99
describe "priority queue" do
1010
before do
11+
# Anchor the vendored Persistent classes on the real Gem::Net::HTTP
12+
# before Artifice replaces it, see Artifice.activate_with. Requiring
13+
# support/artifice/compact_index already activates Artifice, so this
14+
# must come first.
15+
require "bundler/vendored_persistent"
1116
require "support/artifice/compact_index"
1217
Artifice.activate_with(CompactIndexAPI)
1318

@@ -98,6 +103,11 @@
98103
skip "This example does not work under a parent make jobserver"
99104
end
100105

106+
# Anchor the vendored Persistent classes on the real Gem::Net::HTTP
107+
# before Artifice replaces it, see Artifice.activate_with. Requiring
108+
# support/artifice/compact_index already activates Artifice, so this
109+
# must come first.
110+
require "bundler/vendored_persistent"
101111
require "support/artifice/compact_index"
102112
Artifice.activate_with(CompactIndexAPI)
103113

spec/support/artifice/helpers/artifice.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ module Artifice
99
# Rack endpoint.
1010
#
1111
# @param [#call] endpoint A valid Rack endpoint
12+
# In-process users that also deactivate must load bundler/vendored_persistent
13+
# before activating. If it gets lazily required while Artifice is active, the
14+
# vendored Persistent classes are defined under the Artifice replacement of
15+
# Gem::Net::HTTP instead of the real one, and after deactivation
16+
# Gem::Net::HTTP::Persistent becomes unresolvable, blowing up the
17+
# connection_pool fork hook on any later Process.fork. Spawned bundler
18+
# processes are unaffected: they never deactivate, and requiring it here
19+
# would double-load bundler files in them through mismatched load paths.
1220
def self.activate_with(endpoint)
1321
require_relative "rack_request"
1422

0 commit comments

Comments
 (0)