lib/jvertica.rb in jvertica-0.2.2 vs lib/jvertica.rb in jvertica-0.2.3
- old
+ new
@@ -174,11 +174,11 @@
raise InvalidObject.new("block or IO object is required.")
end
stream = com.vertica.jdbc.VerticaCopyStream.new(@connection, query)
stream.start
- thread = nil
+ thread = i = nil
begin
if block_given?
i, o = IO.pipe
@@ -186,12 +186,13 @@
thread = Thread.new do
begin
yield(o)
rescue => e
copy_stream_thread.raise e
+ ensure
+ o.close
end
- o.close
end
stream.addStream(org.jruby.util.IOInputStream.new(i))
else
stream.addStream(org.jruby.util.IOInputStream.new(io))
end
@@ -205,9 +206,10 @@
stream.execute
rejects = stream.getRejects
results = stream.finish
ensure
thread.join unless thread.nil?
+ i.close rescue nil
end
[results, rejects.to_ary]
end
end