Forum: Ruby Process Leak after using Session module

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Pra B. (Guest)
on 2009-05-28 02:37
Hi,

This script has a process leak with a bash session being left open every
time I run it.  I can't find a way to close the bash object after I am
done. Docs don't explicitly don't cover this.. or I am missing something
simple. Can anyone shed some light on this or point to docs that I may
not be aware of? I looked at the readme provided by Sessions module
authors so far.

Thanks in advance.

Prakash



bash = Session::Shell.new

  oratab_file = Oratab()
  ofile = File.open(oratab_file, "r")
  ############################################################
  # Looping through all lines
  ############################################################
   bash.execute ">instancestatus-output.txt"
   ofile.each { |oratab_line|
     if oratab_line =~ /^\s+/
     else
       if oratab_line =~ /^#/
       else
         if oratab_line =~ /^\+/
         else
           db_str = db_and_flag(oratab_line)
           db_arr = db_str.split(",")
           db_name = db_arr[0]
           puts db_name

           #########################################################
           # Make calls to the right database calls right here
           ##########################################################
           bash.execute "echo #{db_name}:>>instancestatus-output.txt"
           bash.execute "InstanceStatus.sh #{db_name}", 1 => STDOUT, 2
=> STDERR do |out,err|
             puts out if out
             puts err if err
           end
           ##########################################################
           # End of loop for bash.execute
           ##########################################################
         end
       end
     end
# /* end of the ofile.each statement */
#################################################################
#
#
#################################################################
}
end
Tim P. (Guest)
on 2009-05-28 19:59
(Received via mailing list)
On Wed, May 27, 2009 at 4:38 PM, Pra B. <removed_email_address@domain.invalid>
wrote:
> Hi,
>
> This script has a process leak with a bash session being left open every
> time I run it.  I can't find a way to close the bash object after I am
> done. Docs don't explicitly don't cover this.. or I am missing something
> simple. Can anyone shed some light on this or point to docs that I may
> not be aware of? I looked at the readme provided by Sessions module
> authors so far.
>

Just a guess here, but try closing your oratab_file descriptor. The
bash shell will usually hang around if there are open file descriptors
or child processes running. If closing the file descriptor does not
work, then try looking for open sockets or running children.

oratab_file = Oratab()
File.open(oratab_file, 'r') do |ofile|
  bash.execute ">instancestatus-output.txt"
  ofile.each { |oratab_line|
    ...
  }
end


Blessings,
TwP
Robert K. (Guest)
on 2009-05-28 22:56
(Received via mailing list)
On 28.05.2009 17:58, Tim P. wrote:
> On Wed, May 27, 2009 at 4:38 PM, Pra B. <removed_email_address@domain.invalid> wrote:

>   }
> end
>

Guessing here as well: maybe bash.close helps.

My 0.02 EUR...

  robert
Pra B. (Guest)
on 2009-05-29 00:02
That was it! Your .02 EUR was wprth a lot for me today.  Is there some
documentation where I could have found that bit of nugget?

Thanks a bunch...


Robert K. wrote:
> On 28.05.2009 17:58, Tim P. wrote:
>> On Wed, May 27, 2009 at 4:38 PM, Pra B. <removed_email_address@domain.invalid> wrote:
>
>>   }
>> end
>>
>
> Guessing here as well: maybe bash.close helps.
>
> My 0.02 EUR...
>
>   robert
Robert K. (Guest)
on 2009-05-29 00:41
(Received via mailing list)
On 28.05.2009 22:02, Pra B. wrote:
> That was it! Your .02 EUR was wprth a lot for me today.  Is there some
> documentation where I could have found that bit of nugget?

I have no idea: I had this idea of #close and briefly tried to find
documentation but hit only source code.  So I voiced it nevertheless.

The basic reasoning was, if you open the session with Session.new it
probably also needs to be closed. :-)

> Thanks a bunch...

You're welcome!  I'm glad my wild guess was of help.

Kind regards

  robert
This topic is locked and can not be replied to.