From f91879a7b548284c93743168acfd11e3d2aeefac Mon Sep 17 00:00:00 2001 From: "NARUSE, Yui" Date: Wed, 10 Jul 2019 15:49:10 +0900 Subject: [PATCH] handle_interrupt to defend monitor state [Bug #15992] If an exception is raised from another thread for example Timeout and this thread is just after `mon_exit`'s `@mon_owner = nil`, the exception breaks the state of MonitorMixin. To prevent that situation, it need to block interruption in mon_enter and mon_exit. --- lib/monitor.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/monitor.rb b/lib/monitor.rb index 90847cf330..044219bcbb 100644 --- a/lib/monitor.rb +++ b/lib/monitor.rb @@ -225,11 +225,13 @@ module MonitorMixin # +MonitorMixin+. # def mon_synchronize - mon_enter + # Prevent interrupt on handling interrupts; for example timeout errors + # it may break locking state. + Thread.handle_interrupt(Exception => :never){ mon_enter } begin yield ensure - mon_exit + Thread.handle_interrupt(Exception => :never){ mon_exit } end end alias synchronize mon_synchronize