diff --git a/lib/gdk/diagnostic.rb b/lib/gdk/diagnostic.rb index ee0d7d1..c72e187 100644 --- a/lib/gdk/diagnostic.rb +++ b/lib/gdk/diagnostic.rb @@ -10,6 +10,7 @@ require_relative 'diagnostic/geo' require_relative 'diagnostic/git' require_relative 'diagnostic/ruby_gems' +require_relative 'diagnostic/re2' module GDK module Diagnostic @@ -23,6 +24,7 @@ def self.all PendingMigrations Geo Status + Re2 ] klasses.map do |const| diff --git a/lib/gdk/diagnostic/re2.rb b/lib/gdk/diagnostic/re2.rb new file mode 100644 index 0000000..7c0763b --- /dev/null +++ b/lib/gdk/diagnostic/re2.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require 'open3' + +module GDK + module Diagnostic + class Re2 < Base + TITLE = 're2' + SCRIPT = "require 're2'; regexp = RE2::Regexp.new('{', log_errors: false); regexp.error unless regexp.ok?" + + def diagnose + # When re2 and libre2 are out of sync, a seg fault can occur due + # to some memory corruption (https://github.com/mudge/re2/issues/43). + # This test doesn't always fail the first time, so repeat the test + # several times to be sure. + 5.times do + @stdout, @stderr, @status = Open3.capture3('ruby', '-e', SCRIPT) + break unless @status.success? + end + end + + def success? + @status.success? && @stdout.empty? && @stderr.empty? + end + + def detail + <<~MESSAGE + It looks like your system re2 library may have been upgraded, and + the re2 gem needs to be rebuilt as a result. + + Please run `gem pristine re2`. + MESSAGE + end + end + end +end diff --git a/spec/lib/gdk/diagnostic_spec.rb b/spec/lib/gdk/diagnostic_spec.rb index 221843c..426d1ee 100644 --- a/spec/lib/gdk/diagnostic_spec.rb +++ b/spec/lib/gdk/diagnostic_spec.rb @@ -17,7 +17,8 @@ GDK::Diagnostic::Dependencies, GDK::Diagnostic::PendingMigrations, GDK::Diagnostic::Geo, - GDK::Diagnostic::Status + GDK::Diagnostic::Status, + GDK::Diagnostic::Re2 ] expect(described_class.all.map(&:class)).to eq(diagnostic_classes)