summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBarrett Ingram <barrettkingram@gmail.com>2021-07-03 07:55:57 -0500
committerGitHub <noreply@github.com>2021-07-03 15:55:57 +0300
commitd6f31838757d3a490b3d368994115875eed798c9 (patch)
tree7da4ab43bccd118cb05d994548cd5d9a172cceaf /lib
parent58a026d8f1e4a2d31dc782d29333647b58d58714 (diff)
downloadpry-d6f31838757d3a490b3d368994115875eed798c9.tar.gz
Return with an error message if pry is started inside signal handler (#2206)
Mutex#synchronize will throw an error if called from code passed to Signal.trap. This makes it impossible to start a working Pry session inside a signal handler. Currently, calling binding.pry inside signal handling code raises an exception because Pry uses mutexes to solve various thread-safety issues. This commit updates Pry.start to detect whether we'll have the ability to use Mutex#synchronize. If not, we'll print an error message and return instead of raising an error. https://github.com/pry/pry/issues/2191
Diffstat (limited to 'lib')
-rw-r--r--lib/pry/pry_class.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb
index 651cf67e..f5f8db6a 100644
--- a/lib/pry/pry_class.rb
+++ b/lib/pry/pry_class.rb
@@ -168,6 +168,12 @@ you can add "Pry.config.windows_console_warning = false" to your pryrc.
return
end
+ unless mutex_available?
+ output.puts "ERROR: Unable to obtain mutex lock."
+ output.puts "This can happen if binding.pry is called from a signal handler"
+ return
+ end
+
options[:target] = Pry.binding_for(target || toplevel_binding)
initial_session_setup
final_session_setup
@@ -378,6 +384,13 @@ Readline version #{Readline::VERSION} detected - will not auto_resize! correctly
ensure
Thread.current[:pry_critical_section] -= 1
end
+
+ def self.mutex_available?
+ Mutex.new.synchronize { true }
+ rescue ThreadError
+ false
+ end
+ private_class_method :mutex_available?
end
Pry.init