Guard against spurious interrupt in interruptible_region

This commit is contained in:
Nicolas Viennot 2013-06-26 15:03:47 -04:00
parent d357903600
commit d213b5c7b6
1 changed files with 12 additions and 2 deletions

View File

@ -91,6 +91,9 @@ class Pry
@interruptible = true
end
# XXX Note that there is a chance that we get the interrupt right after
# the readline call succeeded, but we'll never know, and we will retry the
# call, discarding that piece of input.
block.call
rescue Interrupt
@ -99,9 +102,16 @@ class Pry
retry
ensure
# Once we leave, we cannot receive an Interrupt, as it might disturb code
# Once we leave, we cannot receive an interrupt, as it might disturb code
# that is not tolerant to getting an exception in random places.
@mutex.synchronize { @interruptible = false }
# Note that we need to guard against a spurious interrupt delivered while
# we are trying to acquire the lock (the rescue block is no longer in our
# scope).
begin
@mutex.synchronize { @interruptible = false }
rescue Interrupt
retry
end
end
end
end