FIX: ensure thread is always stopped on timeout

FIX: ensure thread is always stopped on timeout

This ensures that even if we see an exception we will take care of stopping the timeout thread.

Previously the race condition left an edge case where thread would terminate after pipe was closed

diff --git a/CHANGELOG b/CHANGELOG
index 00e2d02..c028069 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,8 @@
+- 0.2.8
+
+- 11-11-2019
+
+  - FIX: ensure thread live cycle is properly accounter for following file descriptor fix
 
 - 0.2.7
 
diff --git a/lib/mini_racer.rb b/lib/mini_racer.rb
index 83da2bb..37858ec 100644
--- a/lib/mini_racer.rb
+++ b/lib/mini_racer.rb
@@ -313,9 +313,15 @@ module MiniRacer
 
       # ensure we do not leak a thread in state
       t.join
+      t = nil
 
       rval
     ensure
+      # exceptions need to be handled
+      if t && wp
+        wp.write("done")
+        t.join
+      end
       wp.close if wp
       rp.close if rp
     end
diff --git a/lib/mini_racer/version.rb b/lib/mini_racer/version.rb
index 284fd28..a7f9c71 100644
--- a/lib/mini_racer/version.rb
+++ b/lib/mini_racer/version.rb
@@ -1,3 +1,3 @@
 module MiniRacer
-  VERSION = "0.2.7"
+  VERSION = "0.2.8"
 end

GitHub sha: 63a13bf7

1 Like