[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Got SystemStackError exception: stack level too deep

Bezan Kapadia

2/9/2009 11:13:00 PM

I have master Process that is forking 2 child processes in the
background.

Now one of the child process is sending a mail out to me using the smtp
server every minute.

After about 20 hours I get the following error below:
Got Timeout::Error exception: execution expired
Got SystemExit exception: exit

Am guessing the above error is to with the slow server Network.
The program continues fine because I have trapped the exception using
"rescue".

After about 6 hours I get the following:
Got SystemStackError exception: stack level too deep

Once I get this error my entire program begins to bomb and work
incorrectly.

Can someone explain what does this error really mean "Got
SystemStackError exception: stack level too deep" ?
and if there are anything to look for or keep in mind to contain or
prevent this error or some kind of work around etc...?

Thanks in advance
--
Posted via http://www.ruby-....

15 Answers

Tony Arcieri

2/9/2009 11:34:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

On Mon, Feb 9, 2009 at 4:12 PM, Bezan Kapadia <bezan99@gmail.com> wrote:

> Can someone explain what does this error really mean "Got
> SystemStackError exception: stack level too deep" ?
> and if there are anything to look for or keep in mind to contain or
> prevent this error or some kind of work around etc...?
>

It means that you have too many calls to functions which are in turn calling
other functions before returning. A quick and easy way to cause a similar
error is:

def foo; foo; end
foo

The stack trace you get with the SystemStackError will be enormously helpful
in diagnosing this problem. Perhaps you can paste it to the list?

--
Tony Arcieri

Bezan Kapadia

2/10/2009 12:29:00 AM

0

I see ...

My code below : The function 1 calls the function mail_system every 60
seconds.

Take a look at my 2 functions below and can u suggest of what should I
really change to do away with this issue

require 'net/smtp'

def mail_system(message,i)

user=`echo $USER`.chomp
recipient=user+"@gmail.com"
msg = "#{message}"
Net::SMTP.start('smtp.gmail.com',25) do |smtp|
smtp.send_message(msg, "#{recipient}", "#{recipient}")
Notification for Email Sent completion - #{message}"
end
rescue Timeout::Error => e
$mes_trace.error("Got #{e.class} exception: #{e.message}")
puts "Got #{e.class} exception: #{e.message}"
exit false
end



def function1
........
mail_system(message,i)
rescue Exception => e
$mes_trace.error("Got #{e.class} exception: #{e.message}")
puts "Got #{e.class} exception: #{e.message}"
end

sleep(60)
end






Tony Arcieri wrote:
> On Mon, Feb 9, 2009 at 4:12 PM, Bezan Kapadia <bezan99@gmail.com> wrote:
>
>> Can someone explain what does this error really mean "Got
>> SystemStackError exception: stack level too deep" ?
>> and if there are anything to look for or keep in mind to contain or
>> prevent this error or some kind of work around etc...?
>>
>
> It means that you have too many calls to functions which are in turn
> calling
> other functions before returning. A quick and easy way to cause a
> similar
> error is:
>
> def foo; foo; end
> foo
>
> The stack trace you get with the SystemStackError will be enormously
> helpful
> in diagnosing this problem. Perhaps you can paste it to the list?

--
Posted via http://www.ruby-....

Jayce Meade

2/10/2009 12:46:00 AM

0

Notification for Email Sent completion - #{message}"
end

It looks to me like you have an " to terminate a string but you donâ??t have
one to begin it. Because of that, It's probably encountering the word 'for'
and interpreting it as a loop construct and it just goes over and over and
over since there's nothing to break the loop. My guess is that the root of
the stack level error is in the code being taken as part of the loop...

Maybe I missed it, if so, I apologize, but that's what it looks like to me.
Hope it helps.

- jayce

--------------------------------------------------
From: "Bezan Kapadia" <bezan99@gmail.com>
Sent: Monday, February 09, 2009 4:28 PM
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Subject: Re: Got SystemStackError exception: stack level too deep

> I see ...
>
> My code below : The function 1 calls the function mail_system every 60
> seconds.
>
> Take a look at my 2 functions below and can u suggest of what should I
> really change to do away with this issue
>
> require 'net/smtp'
>
> def mail_system(message,i)
>
> user=`echo $USER`.chomp
> recipient=user+"@gmail.com"
> msg = "#{message}"
> Net::SMTP.start('smtp.gmail.com',25) do |smtp|
> smtp.send_message(msg, "#{recipient}", "#{recipient}")
> Notification for Email Sent completion - #{message}"
> end
> rescue Timeout::Error => e
> $mes_trace.error("Got #{e.class} exception: #{e.message}")
> puts "Got #{e.class} exception: #{e.message}"
> exit false
> end
>
>
>
> def function1
> ........
> mail_system(message,i)
> rescue Exception => e
> $mes_trace.error("Got #{e.class} exception: #{e.message}")
> puts "Got #{e.class} exception: #{e.message}"
> end
>
> sleep(60)
> end
>
>
>
>
>
>
> Tony Arcieri wrote:
>> On Mon, Feb 9, 2009 at 4:12 PM, Bezan Kapadia <bezan99@gmail.com> wrote:
>>
>>> Can someone explain what does this error really mean "Got
>>> SystemStackError exception: stack level too deep" ?
>>> and if there are anything to look for or keep in mind to contain or
>>> prevent this error or some kind of work around etc...?
>>>
>>
>> It means that you have too many calls to functions which are in turn
>> calling
>> other functions before returning. A quick and easy way to cause a
>> similar
>> error is:
>>
>> def foo; foo; end
>> foo
>>
>> The stack trace you get with the SystemStackError will be enormously
>> helpful
>> in diagnosing this problem. Perhaps you can paste it to the list?
>
> --
> Posted via http://www.ruby-....
>
>

Bezan Kapadia

2/10/2009 12:57:00 AM

0

ahh No ...thats the issue with my cut copy paste .. sorry I pasted that
incorrectly here..I have pasted that line correctly below..
puts "Notification for Email Sent completion - #{message}"


>>stack trace you get with the SystemStackError will be enormously helpful
Where do I get this from..?


Jayce Meade wrote:
> Notification for Email Sent completion - #{message}"
> end
>
> It looks to me like you have an " to terminate a string but you donâ??t
> have
> one to begin it. Because of that, It's probably encountering the word
> 'for'
> and interpreting it as a loop construct and it just goes over and over
> and
> over since there's nothing to break the loop. My guess is that the root
> of
> the stack level error is in the code being taken as part of the loop...
>
> Maybe I missed it, if so, I apologize, but that's what it looks like to
> me.
> Hope it helps.
>
> - jayce
>
> --------------------------------------------------
> From: "Bezan Kapadia" <bezan99@gmail.com>
> Sent: Monday, February 09, 2009 4:28 PM
> Newsgroups: comp.lang.ruby
> To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
> Subject: Re: Got SystemStackError exception: stack level too deep

--
Posted via http://www.ruby-....

Jayce Meade

2/10/2009 1:12:00 AM

0

if this is all in a single file you should paste all of it. it seems it's
missing some code and you should also paste the whole error.

-jayce

--------------------------------------------------
From: "Bezan Kapadia" <bezan99@gmail.com>
Sent: Monday, February 09, 2009 4:57 PM
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Subject: Re: Got SystemStackError exception: stack level too deep

> ahh No ...thats the issue with my cut copy paste .. sorry I pasted that
> incorrectly here..I have pasted that line correctly below..
> puts "Notification for Email Sent completion - #{message}"
>
>
>>>stack trace you get with the SystemStackError will be enormously helpful
> Where do I get this from..?
>
>
> Jayce Meade wrote:
>> Notification for Email Sent completion - #{message}"
>> end
>>
>> It looks to me like you have an " to terminate a string but you donâ??t
>> have
>> one to begin it. Because of that, It's probably encountering the word
>> 'for'
>> and interpreting it as a loop construct and it just goes over and over
>> and
>> over since there's nothing to break the loop. My guess is that the root
>> of
>> the stack level error is in the code being taken as part of the loop...
>>
>> Maybe I missed it, if so, I apologize, but that's what it looks like to
>> me.
>> Hope it helps.
>>
>> - jayce
>>
>> --------------------------------------------------
>> From: "Bezan Kapadia" <bezan99@gmail.com>
>> Sent: Monday, February 09, 2009 4:28 PM
>> Newsgroups: comp.lang.ruby
>> To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
>> Subject: Re: Got SystemStackError exception: stack level too deep
>
> --
> Posted via http://www.ruby-....
>
>

Bezan Kapadia

2/10/2009 2:07:00 AM

0

Well there are multiple Files and its complicated.. but I think the
issue definately lies some where in the part of the code that I have
pasted above.

The scripts have run days in the background and the error that I have
pasted is all that is there in the trace File.

--
Posted via http://www.ruby-....

Jayce Meade

2/10/2009 2:18:00 AM

0

Trace file? If you're sending attachments, I don't thing the mailing list
allows them.

--------------------------------------------------
From: "Bezan Kapadia" <bezan99@gmail.com>
Sent: Monday, February 09, 2009 6:07 PM
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Subject: Re: Got SystemStackError exception: stack level too deep

> Well there are multiple Files and its complicated.. but I think the
> issue definately lies some where in the part of the code that I have
> pasted above.
>
> The scripts have run days in the background and the error that I have
> pasted is all that is there in the trace File.
>
> --
> Posted via http://www.ruby-....
>
>

Tony Arcieri

2/10/2009 2:19:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

On Mon, Feb 9, 2009 at 7:07 PM, Bezan Kapadia <bezan99@gmail.com> wrote:

> The scripts have run days in the background and the error that I have
> pasted is all that is there in the trace File.
>

Can you provide the complete stack trace associated with the
SystemStackError?

--
Tony Arcieri
medioh.com

Jayce Meade

2/10/2009 2:45:00 AM

0

Perhaps your error-checking code is causing the program to restart when the
error crops up. If so, it might lead to the stack error. If say, every six
hours, something changes (I think that's how long you said it took) and it
causes an error, the original error is caught and the program
continues/restarts execution. If the error trapping code restarts by calling
the methods used to start the script in the first place, it would turn into
a stack error if it's not done correctly.

It would be like writing something on a piece of paper. Say once this
figurative piece of paper is full, the stack error crops up. If your program
error is equivalent to the end of a line of text on this piece of paper,
after every error, or line, the program restarts, or a new line is started.
The problem here is that as the errors or lines of text add up on this piece
of paper, eventually, the paper is full, and you can't write anything else
on it, and the StackError pops up.

Basically put, your program may be just writing line after line to this
piece of paper rather than starting with a clean sheet every time it
restarts. What you want to do is go all the way back up to the program's
initiation, where the first line of code used to start the program is, and
set up your error rescuing code there, that way, the error is caught where
the program begins, and you can safely restart it because that's where the
program started in the first place.

This probably isn't even proper syntax, but bear with me:

def method1() # B
#...
rescue Exception # C
# restarting code here
end

method1() # A

###

A is the last line where method1 is called.
B is where method1 is defined/executed
C is where you have your error catching code

Right here, its basically doing this:

A -> B -> Error pops up -> Rescued by C in the context of B -> A -> B ->
Error - > rescued by C in the context of B -> A and so on.

You want it to do this instead:

def method1 #B
#...
end

begin
method1() # A

rescue Exception #C
#... Error catching code here, maybe output to console
retry

end


this time, it's doing this:

A -> B -> Error pops up -> Rescued and restarted by C in top - level
context -> Program restarts, executing line A in top-level context

In this one, instead of restarting in the context of B, it's going all the
way back to the top level of execution and restarting from there, rather
than in the context of the program's execution code itself.

A good way to set up an error system so you know what happened and where,
and specifically why it happened is to raise a runtime error like so and
then catch it later:

def method1
# ...
rescue Exception => e
raise("Errored in method1: #{e}")
end
end

begin
method1()

rescue RuntimeError => e
puts e
# .. what to do next
end

Hope that all made sense! =P

Hope it helps, too. From what I've learned you want to restart your
program from where it was started initially to avoid things building up and
getting problematic.

- jayce

--------------------------------------------------
From: "Jayce Meade" <azimuth-rubytalk@live.com>
Sent: Monday, February 09, 2009 6:17 PM
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Subject: Re: Got SystemStackError exception: stack level too deep

> Trace file? If you're sending attachments, I don't thing the mailing list
> allows them.
>
> --------------------------------------------------
> From: "Bezan Kapadia" <bezan99@gmail.com>
> Sent: Monday, February 09, 2009 6:07 PM
> Newsgroups: comp.lang.ruby
> To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
> Subject: Re: Got SystemStackError exception: stack level too deep
>
>> Well there are multiple Files and its complicated.. but I think the
>> issue definately lies some where in the part of the code that I have
>> pasted above.
>>
>> The scripts have run days in the background and the error that I have
>> pasted is all that is there in the trace File.
>>
>> --
>> Posted via http://www.ruby-....
>>
>>
>
>

Brian Candler

2/10/2009 1:45:00 PM

0

Bezan Kapadia wrote:
> rescue Timeout::Error => e
> $mes_trace.error("Got #{e.class} exception: #{e.message}")
> puts "Got #{e.class} exception: #{e.message}"

puts e.backtrace.join("\n")

This should give you the backtrace you need to understand what's
happening. (Although sometimes I think it can be garbled in the case of
a stack overflow error)
--
Posted via http://www.ruby-....