JRuby and open-uri File handle issue

As stated in another thread we have been seeing the number of open file
handles increase through out the day until Tomcat is restarted.

We are using Rails 2.3.5 with Tomcat 5 OpenJDK 1.6.0-b09 and Jruby 1.4
on RHEL 5.4.

I have finally tracked down the culprit. Using open-uri like so:

open(“http://www.google.com”) {|f|
f.each_line {|line| p line}

Causes following to be added to the tomcat lsof entries:

java 20153 tomcat 95r FIFO 0,6 12572360
java 20153 tomcat 99w FIFO 0,6 12572360
java 20153 tomcat 100r 0000 0,11 0 12572361

These are not released until Tomcat is restarted. Note that there are
always two “pipes” and 1 eventpoll entry added each time the open
function is executed.

Any ideas on this one? Is this a known issue?

NOTE: its not specific to the open-uri wrapper. The problem is down in
the net/http class somewhere.

I can duplicate with the following as well:

Net::HTTP.get_print URI.parse(‘Example Domain’)

I have setup a test outside of rails an Tomcat:

require ‘open-uri’

x = open(“http://www.lecza.com”)
puts x.read
x = nil
puts STDIN.read

When I run the code above with Ruby those handles are not stuck (while
on the read)

When I run it with Jruby I see the handles stuck until I terminate the

I tried Jruby 1.4.0 and 1.5.0 RC2 and both have the same issue.

FYI - I opened a bug: http://jira.codehaus.org/browse/JRUBY-4767