FIX: ensure we release pipe fds early

FIX: ensure we release pipe fds early

Previously we relied on GC to release pipe fds. This worked on earlier versions of Ruby but on 2.7 it will start breaking.

We now release the fds early to avoid the issues.

diff --git a/.travis.yml b/.travis.yml
index c9933f4..6d7abae 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,6 +3,7 @@ rvm:
   - 2.3
   - 2.4
   - 2.5
+  - 2.6
   - ruby-head
 matrix:
   include:
diff --git a/CHANGELOG b/CHANGELOG
index e2b880a..00e2d02 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,10 @@
+
+- 0.2.7
+
+- 11-11-2019
+
+  - FIX: release the file descriptor for timeout pipe earlier (this avoids holding too many files open in Ruby 2.7)
+
 - 14-05-2019
 
 - 0.2.6
diff --git a/lib/mini_racer.rb b/lib/mini_racer.rb
index 4f15b65..83da2bb 100644
--- a/lib/mini_racer.rb
+++ b/lib/mini_racer.rb
@@ -315,7 +315,9 @@ module MiniRacer
       t.join
 
       rval
-
+    ensure
+      wp.close if wp
+      rp.close if rp
     end
 
     def check_init_options!(options)
diff --git a/lib/mini_racer/version.rb b/lib/mini_racer/version.rb
index d628775..284fd28 100644
--- a/lib/mini_racer/version.rb
+++ b/lib/mini_racer/version.rb
@@ -1,3 +1,3 @@
 module MiniRacer
-  VERSION = "0.2.6"
+  VERSION = "0.2.7"
 end
diff --git a/test/mini_racer_test.rb b/test/mini_racer_test.rb
index 7a57511..3d4c4ca 100644
--- a/test/mini_racer_test.rb
+++ b/test/mini_racer_test.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require 'securerandom'
 require 'date'
 require 'test_helper'
@@ -731,7 +733,7 @@ raise FooError, "I like foos"
     isolate = MiniRacer::Isolate.new
     context = MiniRacer::Context.new(isolate: isolate)
     context.dispose
-    context2 = MiniRacer::Context.new(isolate: isolate) # Received signal 11 SEGV_MAPERR
+    _context2 = MiniRacer::Context.new(isolate: isolate) # Received signal 11 SEGV_MAPERR
   end
 
   def test_context_starts_with_no_isolate_value
@@ -757,7 +759,6 @@ raise FooError, "I like foos"
   end
 
   def test_heap_dump
-
     f = Tempfile.new("heap")
     path = f.path
     f.unlink
@@ -771,6 +772,15 @@ raise FooError, "I like foos"
     assert dump.length > 0
 
     FileUtils.rm(path)
+  end
 
+  def test_pipe_leak
+    # in Ruby 2.7 pipes will stay open for longer
+    # make sure that we clean up early so pipe file
+    # descriptors are not kept around
+    context = MiniRacer::Context.new(timeout: 1000)
+    10000.times do |i|
+      context.eval("'hello'")
+    end
   end
 end

GitHub sha: b5ef1d1a

1 Like