Skip to content

File Descriptors Not Released After GC.start #221

@sgonyea

Description

@sgonyea

In MRI, running the following code:

$$
# => 11989
10.times { f = File.open("/tmp/foo", "w") }

Creates 10 open file descriptors; even though f is not referenced, the file descriptor remains. JRuby also behaves this way.

lsof -p 11989 | grep "/tmp/foo" | wc -l
#10

Now if I do:

GC.start

lsof will no longer show any open file descriptors. wc -l is 1. JRuby does not do this. I can't seem to get JRuby to collect open file descriptors on a Garbage Collection. Any thoughts? I discovered this bug while sanity-checking my fix for this issue:

padrino/padrino-framework#877

Initially, I "fixed" the issue by no longer caching the file descriptor. This should have resolved the issue, but the file descriptors stuck around, even after a garbage collection. GC.start seems to do nothing. One thing I did notice, is if I forced a garbage collection from VisualVM then all but one of the file descriptors would be collected (just like MRI).

So, I'm not sure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions