Bug #15866 main.sp fails (thread stack limit insufficient for recursive call "fib(20)")
Submitted: 19 Dec 2005 18:26 Modified: 10 Jul 2009 15:19
Reporter: Joerg Bruehe Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.17 OS:Any (Various Unix)
Assigned to: Bernt Marius Johnsen CPU Architecture:Any
Tags: pb2, test failure

[19 Dec 2005 18:26] Joerg Bruehe
Description:
Tast "sp" fails on many platforms, in all cases due to stack space limits
(checked at runtime, leading to exit - no crash):

sp                             [ fail ]

Errors are (from PATH/mysqltest-time) :
mysqltest: At line NNN: query 'call fib(20)' failed: 1436: Thread stack overrun:  185200 bytes used of a 262144 byte stack, and 81920 bytes needed.  Use 'mysqld -O thread_stack=#' to specify a bigger stack.
(the last lines may be the most important ones)

Varying values:

185200 bytes used of a 262144 byte stack
butch-64bit-5.0-debug.log   normal
butch-64bit-5.0-debug.log   ps-protocol
sol10-sparc-a-64bit-5.0-debug.log   normal
sol10-sparc-a-64bit-5.0-debug.log   ps-protocol
sunfire100a-64bit-5.0-debug.log   normal
sunfire100a-64bit-5.0-debug.log   ps-protocol

183760 bytes used of a 262144 byte stack
hp3750-64bit-5.0-debug.log   normal
hp3750-64bit-5.0-debug.log   ps-protocol
hpux11-64bit-5.0-debug.log   normal
hpux11-64bit-5.0-debug.log   ps-protocol

118624 bytes used of a 196608 byte stack
intelxeon3-5.0-debug.log   normal
intelxeon3-5.0-debug.log   ps-protocol
sol9x86-5.0-debug.log   normal
sol9x86-5.0-debug.log   ps-protocol

121152 bytes used of a 196608 byte stack
opnsrv6c-5.0-debug.log   normal
opnsrv6c-5.0-debug.log   ps-protocol

120112 bytes used of a 196608 byte stack
sol10-sparc-a-5.0-debug.log   normal
sol10-sparc-a-5.0-debug.log   ps-protocol
sunfire100b-5.0-debug.log   normal
sunfire100b-5.0-debug.log   ps-protocol
sunfire100c-5.0-debug.log   normal
sunfire100c-5.0-debug.log   ps-protocol

120092 bytes used of a 196608 byte stack
sol10-x86-5.0-debug.log   normal
sol10-x86-5.0-debug.log   ps-protocol

How to repeat:
Test suite failure,
but occurring only with "debug" builds.

Suggested fix:
Three alternatives:
a) Increase thread stack size
   (would increase address space usage even for simple uses, not good)
b) Reduce the "resevre" of 80 kB
   (I cannot tell whether that would be safe)
c) Reduce the recursion depth of the test, say from 20 to 15 or 10
   (Unsure whether that is enough, but worth a try).
[5 Jan 2006 0:37] Gary Casterline
I'm seeing this on a non-debug build on solaris 9  with forte compiler.
[5 Jan 2006 6:38] Gary Casterline
I should add this was version 5.0.18 on sparc solaris 9 building with forte compilers.
[19 Jan 2006 16:29] Per-Erik Martin
It seems the only solution is to lower the count in the call. (On my suse 10 it manages 36 before it hits the limit, but apparently 20 is too much on some other machines.)

Note that the table 'fib' is removed if the test proceeded, but apparently the entire test file is aborted when this error occurs. (So renaming the table will not really help, eventhough that should perhaps be done anyway.)
[19 Jan 2006 16:55] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/1357
[19 Jan 2006 22:10] Konstantin Osipov
Approved by email
[20 Jan 2006 7:32] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/1384
[20 Jan 2006 7:37] Per-Erik Martin
Pushed to bk 5.0.19

(Set to "documenting", although I'm not sure this needs to be documented. Only a test case was changed.)
[26 Jan 2006 2:48] Mike Hillyer
Documented in 5.0.19 changelog:

   <listitem>
        <para>
          Test suite <literal>sp</literal> test left behind tables when
          the test failed that could cause future tests to fail. (Bug
          #15866)
        </para>
      </listitem>
[4 Jan 2008 13:45] Joerg Bruehe
Even though fht recursion depth was reduced from 20 to 10,
this bug still occurs:

I see it in 5.1.21 and up, and in 6.0.4-alpha,
but only on an IA64 platform if ICC is the compiler used.

So it seems this combination needs more stack space than others.

Here is the 6.0.4-alpha test failure:

main.sp                        [ fail ]

mysqltest: At line NNN: query 'call fib(10)' failed: 1436: Thread stack overrun:  166688 bytes used of a 262144 byte stack,
 and 96000 bytes needed.  Use 'mysqld -O thread_stack=#' to specify a bigger stack.

The result from queries just before the failure was:
< snip >
fetch c into y;
fetch c into x;
close c;
insert into t3 values (x+y);
call fib(n-1);
end;
end if;
end|
set @@max_sp_recursion_depth= 20|
insert into t3 values (0), (1)|
call fib(3)|
select * from t3 order by f asc|
f
0
1
1
2
truncate table t3|
insert into t3 values (0), (1)|
call fib(10)|
[9 Jul 2008 19:35] Joerg Bruehe
Build of 5.1.26-rc :  Still present in Linux/IA64/ICC  in the debug server.
[26 Jan 2009 15:03] Trudy Pelzer
Present in 5.1.31 build; reopening bug.
[24 Feb 2009 11:43] Alexander Nozdrin
XRef2: http://tinyurl.com/b6wy46

In PB2 it's happening regularly on snv platforms.
[2 Jun 2009 11:35] Bernt Marius Johnsen
I will split out the fib() test into a separate test called main.sp-fib.
[2 Jun 2009 11:39] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/75454

2764 Bernt M. Johnsen	2009-06-02
      Bug#15866 The "offendig" part of main.sp has been split out into main.sp-fib as Omer suggested
[2 Jun 2009 13:29] Matthias Leich
Hi Bernt,

ok to push for the splitted test.
Please make a minor modification.
Shrink the phase where warnings are
disabled to the minimum. This means
   --disable_warnings
   drop procedure if exists fib|
   --enable_warnings

   # Now for multiple statements...
   delimiter |;
instead of
   --disable_warnings
   drop procedure if exists fib;

   # Now for multiple statements...
   delimiter |;

   --enable_warnings

Regards

Matthias
[4 Jun 2009 11:39] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/75605

2765 Bernt M. Johnsen	2009-06-04
      Bug#15866 main.sp-fib split from main.sp
[4 Jun 2009 11:54] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/75606

2926 Bernt M. Johnsen	2009-06-04 [merge]
      Bug#15866 ported from 5.0-gca
[4 Jun 2009 13:51] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/75619

3342 Bernt M. Johnsen	2009-06-04 [merge]
      Bug#15866 Merged from 5.1-gca
[4 Jun 2009 14:07] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/75623

3342 Bernt M. Johnsen	2009-06-04 [merge]
      Bug#15866 Split of main.sp and main.sp-fib. Merged from 6.0 gca
[4 Jun 2009 14:10] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/75626

2928 Bernt M. Johnsen	2009-06-04 [merge]
      Bug#15866 Split of main.sp and main.sp-fib. Merged from 5.1 gca
[4 Jun 2009 14:13] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/75628

2766 Bernt M. Johnsen	2009-06-04 [merge]
      Bug#15866 Split of main.sp and main.sp-fib. Merged from 5.0 gca
[9 Jun 2009 8:38] Bernt Marius Johnsen
Re-triage after "offending part" split out into main.sp-fib
[16 Jun 2009 8:32] Bugs System
Pushed into 5.0.84 (revid:gkodinov@mysql.com-20090616082753-kwe0l8uoictxhojf) (version source revid:azundris@mysql.com-20090605212937-9kcqi5zjat2f2awm) (merge vers: 5.0.83) (pib:6)
[16 Jun 2009 11:03] Bugs System
Pushed into 5.1.36 (revid:joro@sun.com-20090616102155-3zhezogudt4uxdyn) (version source revid:azundris@mysql.com-20090606160500-zm37psz7u1m96y5l) (merge vers: 5.1.36) (pib:6)
[17 Jun 2009 19:25] Bugs System
Pushed into 5.4.4-alpha (revid:alik@sun.com-20090616183122-chjzbaa30qopdra9) (version source revid:azundris@mysql.com-20090606160423-aym8s5rn51nmg387) (merge vers: 6.0.12-alpha) (pib:11)
[2 Jul 2009 11:24] Bernt Marius Johnsen
The fib() procedure has two bigint's and a cursor in the stackframe. It seems to be too much in some settings when fib(10) is called. It is not however clear what this test is supposed to actually test. If the aim is to test a recursion depth of 10 or more, a simpler procedure should to the job. If the aim is to test that recursion with cursors on the stack works, the fib(3) call should be sufficient (3 frames on the stack, two of them with a cursor).
[2 Jul 2009 11:43] Bernt Marius Johnsen
Actually, since the test closes the cursor before the recursion, we have no guarantee that teh cursor is working after the recursion, so the question remains: What is this supposed to test????
[2 Jul 2009 12:28] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/77768

2790 Bernt M. Johnsen	2009-07-02
      Bug#15866 1) Move the cursor close to after the recursive call. 2) Change to just one call with recursion depth 4.
[2 Jul 2009 15:59] Matthias Leich
ok to push with two minor changes

1. Please remove the line with
   # 4 recuursion levels should be sufficient
2. Add something like the following comment instead
   (just before the "call fib(4)|")

   # The small number of recursion levels is intentional.
   # We need to avoid
   # Bug#15866 main.sp fails (thread stack limit
   #           insufficient for recursive call "fib(20)")
   # which affects some platforms.

I would like to prevent that the next maintainer/reader of
this test thinks "4" is unnecessary small, increases it
and we get the current bug again.
[3 Jul 2009 8:22] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/77846

2790 Bernt M. Johnsen	2009-07-03
      Bug#15866 Prepared for push on 5.0
[3 Jul 2009 8:27] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/77847

2992 Bernt M. Johnsen	2009-07-03 [merge]
      Bug#15866 Prepared for push on 5.1
[3 Jul 2009 8:31] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/77849

3424 Bernt M. Johnsen	2009-07-03 [merge]
      Bug#15866 Prepared for push on PE branch
[7 Jul 2009 7:52] Bugs System
Pushed into 5.0.84 (revid:joro@sun.com-20090707074938-ksah1ibn0vs92cem) (version source revid:bernt.johnsen@sun.com-20090703083610-o7l4s8syz05rc4w0) (merge vers: 5.0.84) (pib:11)
[8 Jul 2009 13:30] Bugs System
Pushed into 5.1.37 (revid:joro@sun.com-20090708131116-kyz8iotbum8w9yic) (version source revid:bernt.johnsen@sun.com-20090703083217-pveje262esiccyhc) (merge vers: 5.1.37) (pib:11)
[9 Jul 2009 7:35] Bugs System
Pushed into 5.0.84 (revid:joro@sun.com-20090707074938-ksah1ibn0vs92cem) (version source revid:bernt.johnsen@sun.com-20090703083610-o7l4s8syz05rc4w0) (merge vers: 5.0.84) (pib:11)
[9 Jul 2009 7:37] Bugs System
Pushed into 5.1.37 (revid:joro@sun.com-20090708131116-kyz8iotbum8w9yic) (version source revid:bernt.johnsen@sun.com-20090703083217-pveje262esiccyhc) (merge vers: 5.1.37) (pib:11)
[10 Jul 2009 11:21] Bugs System
Pushed into 5.4.4-alpha (revid:anozdrin@bk-internal.mysql.com-20090710111017-bnh2cau84ug1hvei) (version source revid:bernt.johnsen@sun.com-20090703082848-ac0x906mljzc6os9) (merge vers: 5.4.4-alpha) (pib:11)
[10 Jul 2009 15:19] Paul DuBois
Test case changes. No changelog entry needed.
[26 Aug 2009 13:46] Bugs System
Pushed into 5.1.37-ndb-7.0.8 (revid:jonas@mysql.com-20090826132541-yablppc59e3yb54l) (version source revid:jonas@mysql.com-20090826132541-yablppc59e3yb54l) (merge vers: 5.1.37-ndb-7.0.8) (pib:11)
[26 Aug 2009 13:46] Bugs System
Pushed into 5.1.37-ndb-6.3.27 (revid:jonas@mysql.com-20090826105955-bkj027t47gfbamnc) (version source revid:jonas@mysql.com-20090826105955-bkj027t47gfbamnc) (merge vers: 5.1.37-ndb-6.3.27) (pib:11)
[26 Aug 2009 13:48] Bugs System
Pushed into 5.1.37-ndb-6.2.19 (revid:jonas@mysql.com-20090825194404-37rtosk049t9koc4) (version source revid:jonas@mysql.com-20090825194404-37rtosk049t9koc4) (merge vers: 5.1.37-ndb-6.2.19) (pib:11)
[27 Aug 2009 16:33] Bugs System
Pushed into 5.1.35-ndb-7.1.0 (revid:magnus.blaudd@sun.com-20090827163030-6o3kk6r2oua159hr) (version source revid:jonas@mysql.com-20090826132541-yablppc59e3yb54l) (merge vers: 5.1.37-ndb-7.0.8) (pib:11)