memory leak from Hash#delete/fork/drb??

A

Ara.T.Howard

any idea why this leaks memory?


require 'drb/drb'
require 'socket'

class JobRunner
include DRbUndumped
attr :pid
attr :command
def initialize command
@command = command
@pid = fork { exec @command }
end
end

class JobRunnerDaemon
def initialize
@runners = {}
end
def runner command
begin
r = JobRunner::new command
rescue Errno::ENOMEM
GC.start
r = JobRunner::new command
end
@runners[r.pid] = r
r
end
def wait r
pid, status = Process::waitpid2 r.pid, Process::WNOHANG|Process::WUNTRACED
@runners.delete pid
[pid, status]
end
end

$VERBOSE = nil
STDOUT.sync = true
port = Integer(ARGV.shift || (rand(8192 - 1025) + 1025))
uri = "druby://#{ Socket::gethostname }:#{ port }"
pid = fork

if pid
sleep 1
DRb.start_service nil, nil
jrd = DRbObject.new nil, uri
loop{ p(jrd.wait(jrd.runner('echo 42'))) }
else
DRb.start_service uri, JobRunnerDaemon::new
DRb.thread.join
end


when the child is waited on all resources should be freed and the hash entry
blown away - why the leak? what am i doing wrong here?

-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| A flower falls, even though we love it;
| and a weed grows, even though we do not love it.
| --Dogen
===============================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top