Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IO.copy_stream leaves opened files in ObjectSpace #3590

Closed
scarfacedeb opened this issue Jan 10, 2016 · 3 comments
Closed

IO.copy_stream leaves opened files in ObjectSpace #3590

scarfacedeb opened this issue Jan 10, 2016 · 3 comments

Comments

@scarfacedeb
Copy link

It seems to me that JRuby deviates from MRI implementation of IO.copy_stream:

To demonstrate run the following snippet in MRI and jruby:

puts ObjectSpace.each_object(File).reject(&:closed?).count # == 1
IO.copy_stream "README.md", "/tmp/readme"
puts ObjectSpace.each_object(File).reject(&:closed?).count # == 1 in MRI, == 3 in jruby

In MRI IO.copy_stream "README.md", "/tmp/readme" doesn't leave opened files in the ObjectSpace.

But in jruby, ObjectSpace.each_object(File).reject(&:closed?) would include 2 extra implicitly created file descriptors from IO.copy_stream.

It is an expected behaviour?

Relevant refile/refile issue: refile/refile#414

@headius
Copy link
Member

headius commented Jan 21, 2016

Weird. And even weirder that you have a related issue.

@headius
Copy link
Member

headius commented Jan 21, 2016

Tell ya what...I'll at least make sure that streams opened by IO#copy_stream get closed when it's done. They would close due to finalization, so this wasn't really a leak...but it was bad form.

@jowl
Copy link
Contributor

jowl commented Mar 31, 2016

FYI: This also solves another issue I stumbled upon using JRuby 1.7.19, which was that the RubyIO instances could be GC'd during #copy_stream, since they weren't referenced after getting their channels, which caused their finalizers to run and close them. This error appeared as

Errno::EBADF: Bad file descriptor - Bad file descriptor
  copy_stream at org/jruby/RubyIO.java:4694

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants