summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNARUSE, Yui <naruse@airemix.jp>2019-07-10 15:49:10 +0900
committerNARUSE, Yui <naruse@airemix.jp>2019-07-10 18:13:38 +0900
commitf91879a7b548284c93743168acfd11e3d2aeefac (patch)
tree69fed5cf2dee4d3d59ce87e89c5ae77cc80183f4
parent1d2ec4b21647089598d0be3a8bc5f56a71b5e892 (diff)
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.
-rw-r--r--lib/monitor.rb6
1 files 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