Forum: JRuby out of memory error with file IO expected?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
40c8f707cab5f50878cee873881d6b75?d=identicon&s=25 Roger P. (rogerdpack)
on 2013-07-19 19:31
Hello, I noticed when running this code, with 1.7.4:

 100.times { { loop {'big', 'w') do |f|
10_000_000_000; f.puts 'a'; end}}}

after awhile, I got this failure in all threads.  Perhaps the
"directBuffer" is not being freed on close or something, and could be?

 Exception in thread "RubyThread-58: (irb):1"
java.lang.OutOfMemoryError: Direct buffer memory
        at java.nio.Bits.reserveMemory(
        at java.nio.DirectByteBuffer.<init>(
        at java.nio.ByteBuffer.allocateDirect(
        at org.jruby.RubyFile.sysopen(
        at org.jruby.RubyFile.sysopenInternal(
        at org.jruby.RubyFile.openFile19(
        at org.jruby.RubyFile.initialize19(
        at org.jruby.RubyClass.newInstance(
09a41a085f93af8644a7e2e35ba987af?d=identicon&s=25 Charles N. (headius)
on 2013-07-19 21:59
(Received via mailing list)
I believe there was a bug reported where we were not freeing some direct
byte buffers that appears to be fixed in 1.7.5. Can you try master?
0d1cd73bfe0ebe09074bfcd138ed3d5d?d=identicon&s=25 Keith B. (keith_b)
on 2013-07-19 22:23
(Received via mailing list)
I would be surprised if that worked fine. ;)

You're opening the same file in 100 different threads, and writing to it
simultaneously.  There's no guarantee that any given thread's operation
will not be interrupted.

You'd normally want to synchronize access to a resource like that, by
having the many threads post something to a queue, and having 1 thread
reading from the queue and doing the writes.

- Keith
This topic is locked and can not be replied to.