mirror of
https://github.com/rubyjs/mini_racer
synced 2023-03-27 23:21:28 -04:00
FIX: timeout mechanics were not correct
This fix ensures timeout will always be processed correctly, it also adds a safeguard to ensure against race conditions
This commit is contained in:
parent
34e9cedef0
commit
c41db24eb1
3 changed files with 22 additions and 6 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
25-10-2016
|
||||||
|
|
||||||
|
- 0.1.6
|
||||||
|
|
||||||
|
- Fix: timeout behavior was incorrect, in some cases stop could be called on already stopped contexts
|
||||||
|
|
||||||
10-10-2016
|
10-10-2016
|
||||||
|
|
||||||
- 0.1.5
|
- 0.1.5
|
||||||
|
|
|
@ -216,23 +216,33 @@ module MiniRacer
|
||||||
def timeout(&blk)
|
def timeout(&blk)
|
||||||
return blk.call unless @timeout
|
return blk.call unless @timeout
|
||||||
|
|
||||||
_,wp = IO.pipe
|
mutex = Mutex.new
|
||||||
|
done = false
|
||||||
|
|
||||||
|
rp,wp = IO.pipe
|
||||||
|
|
||||||
Thread.new do
|
Thread.new do
|
||||||
begin
|
begin
|
||||||
result = IO.select([wp],[],[],(@timeout/1000.0))
|
result = IO.select([rp],[],[],(@timeout/1000.0))
|
||||||
if !result
|
if !result
|
||||||
stop
|
mutex.synchronize do
|
||||||
|
stop unless done
|
||||||
|
end
|
||||||
end
|
end
|
||||||
rescue
|
rescue => e
|
||||||
|
STDERR.puts e
|
||||||
STDERR.puts "FAILED TO TERMINATE DUE TO TIMEOUT"
|
STDERR.puts "FAILED TO TERMINATE DUE TO TIMEOUT"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
rval = blk.call
|
rval = blk.call
|
||||||
wp.write("done")
|
mutex.synchronize do
|
||||||
|
done = true
|
||||||
|
end
|
||||||
|
|
||||||
|
wp.write("done")
|
||||||
rval
|
rval
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_init_options!(options)
|
def check_init_options!(options)
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
module MiniRacer
|
module MiniRacer
|
||||||
VERSION = "0.1.5"
|
VERSION = "0.1.6"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue