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.
This commit is contained in:
NARUSE, Yui 2019-07-10 15:49:10 +09:00
Родитель 1d2ec4b216
Коммит f91879a7b5
1 изменённых файлов: 4 добавлений и 2 удалений

Просмотреть файл

@ -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