Skip to content

Commit a2ff4b8

Browse files
committed
Fallback to pure the pure ruby path scanner on unexpected error
Fix: #516 Fix: #517 Fix: #521 When we run into what appears to be a libc bug, we fallback to the pure Ruby implementation. That should unblock users, but people willing to help debug this further can set BOOTSNAP_DEBUG=1 to fail on error. The error should indicate which directory failed to open, and perhaps closer inspection will allow to narrow the issue.
1 parent 6003c14 commit a2ff4b8

4 files changed

Lines changed: 14 additions & 2 deletions

File tree

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@ gem "mocha"
1717

1818
group :development do
1919
gem "rubocop", "~> 1.50.2" # Ruby 2.6 support
20+
gem "benchmark"
21+
gem "ostruct"
2022
gem "base64"
2123
end

lib/bootsnap.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
require_relative "bootsnap/version"
44
require_relative "bootsnap/bundler"
5-
require_relative "bootsnap/compile_cache"
6-
require_relative "bootsnap/load_path_cache"
75

86
module Bootsnap
97
InvalidConfiguration = Class.new(StandardError)
@@ -164,3 +162,6 @@ def bool_env(key, default: false)
164162
end
165163
end
166164
end
165+
166+
require_relative "bootsnap/compile_cache"
167+
require_relative "bootsnap/load_path_cache"

lib/bootsnap/load_path_cache/path_scanner.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ def native_call(root_path)
102102
end
103103

104104
all_requirables
105+
rescue SystemCallError => error
106+
if ENV["BOOTSNAP_DEBUG"]
107+
raise
108+
else
109+
Bootsnap.logger&.call("Unexpected error: #{error.class}: #{error.message}")
110+
ruby_call(root_path)
111+
end
105112
end
106113
alias_method :call, :native_call
107114
else

test/test_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
ENV["BOOTSNAP_DEBUG"] = "1"
4+
35
$LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
46

57
if Warning.respond_to?(:[]=)

0 commit comments

Comments
 (0)