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
 | 
			
		||||
 | 
			
		||||
- 0.1.5
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -216,23 +216,33 @@ module MiniRacer
 | 
			
		|||
    def timeout(&blk)
 | 
			
		||||
      return blk.call unless @timeout
 | 
			
		||||
 | 
			
		||||
      _,wp = IO.pipe
 | 
			
		||||
      mutex = Mutex.new
 | 
			
		||||
      done = false
 | 
			
		||||
 | 
			
		||||
      rp,wp = IO.pipe
 | 
			
		||||
 | 
			
		||||
      Thread.new do
 | 
			
		||||
        begin
 | 
			
		||||
          result = IO.select([wp],[],[],(@timeout/1000.0))
 | 
			
		||||
          result = IO.select([rp],[],[],(@timeout/1000.0))
 | 
			
		||||
          if !result
 | 
			
		||||
            stop
 | 
			
		||||
            mutex.synchronize do
 | 
			
		||||
              stop unless done
 | 
			
		||||
            end
 | 
			
		||||
          end
 | 
			
		||||
        rescue
 | 
			
		||||
        rescue => e
 | 
			
		||||
          STDERR.puts e
 | 
			
		||||
          STDERR.puts "FAILED TO TERMINATE DUE TO TIMEOUT"
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      rval = blk.call
 | 
			
		||||
      wp.write("done")
 | 
			
		||||
      mutex.synchronize do
 | 
			
		||||
        done = true
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      wp.write("done")
 | 
			
		||||
      rval
 | 
			
		||||
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def check_init_options!(options)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,3 +1,3 @@
 | 
			
		|||
module MiniRacer
 | 
			
		||||
  VERSION = "0.1.5"
 | 
			
		||||
  VERSION = "0.1.6"
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue