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.
This commit is contained in:
Sam Saffron 2019-11-11 12:20:26 +11:00
parent 9593ff3569
commit b5ef1d1ab6
5 changed files with 24 additions and 4 deletions

View File

@ -3,6 +3,7 @@ rvm:
- 2.3 - 2.3
- 2.4 - 2.4
- 2.5 - 2.5
- 2.6
- ruby-head - ruby-head
matrix: matrix:
include: include:

View File

@ -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 - 14-05-2019
- 0.2.6 - 0.2.6

View File

@ -315,7 +315,9 @@ module MiniRacer
t.join t.join
rval rval
ensure
wp.close if wp
rp.close if rp
end end
def check_init_options!(options) def check_init_options!(options)

View File

@ -1,3 +1,3 @@
module MiniRacer module MiniRacer
VERSION = "0.2.6" VERSION = "0.2.7"
end end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'securerandom' require 'securerandom'
require 'date' require 'date'
require 'test_helper' require 'test_helper'
@ -731,7 +733,7 @@ raise FooError, "I like foos"
isolate = MiniRacer::Isolate.new isolate = MiniRacer::Isolate.new
context = MiniRacer::Context.new(isolate: isolate) context = MiniRacer::Context.new(isolate: isolate)
context.dispose 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 end
def test_context_starts_with_no_isolate_value def test_context_starts_with_no_isolate_value
@ -757,7 +759,6 @@ raise FooError, "I like foos"
end end
def test_heap_dump def test_heap_dump
f = Tempfile.new("heap") f = Tempfile.new("heap")
path = f.path path = f.path
f.unlink f.unlink
@ -771,6 +772,15 @@ raise FooError, "I like foos"
assert dump.length > 0 assert dump.length > 0
FileUtils.rm(path) 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
end end