From cd9a5a2119851263decc561d4a6e61108a8750fb Mon Sep 17 00:00:00 2001 From: Narayanan Iyer Date: Mon, 4 May 2020 09:41:26 -0400 Subject: [PATCH] [DEBUG-ONLY] Bump initial condition handler stack size to avoid nested malloc issues * We had an in-house test failure on an ARMV6L box with the following diff. ```diff > ideminter_rolrec_0/mupipstop_rollback_or_recover/impjob_imptp0.mje5 > %YDB-F-ASSERT, Assert failed in sr_port/gtm_malloc_src.h line 695 for expression (FALSE) ``` Below is the C-stack at the time of the assert failure. ```gdb #0 __pthread_kill () at ../sysdeps/unix/sysv/linux/pthread_kill.c:56 #1 gtm_dump_core () at sr_unix/gtm_dump_core.c:74 #2 ch_cond_core () at sr_unix/ch_cond_core.c:77 #3 rts_error_va () at sr_unix/rts_error.c:192 #4 rts_error_csa () at sr_unix/rts_error.c:99 #5 gtm_malloc () at sr_port/gtm_malloc_src.h:695 #6 condstk_expand () at sr_unix/condstk_expand.c:53 #7 ydb_stm_invoke_deferred_signal_handler () at sr_unix/ydb_stm_invoke_deferred_signal_handler.c:59 #8 deferred_signal_handler () at sr_port/deferred_signal_handler.c:57 #9 gtm_malloc () at sr_port/gtm_malloc_src.h:748 #10 iorm_use () at sr_unix/iorm_use.c:988 #11 iorm_open () at sr_unix/iorm_open.c:254 #12 io_open_try () at sr_unix/io_open_try.c:616 #13 op_open () at sr_port/op_open.c:160 #14 open_source_file () at sr_unix/source_file.c:253 #15 compiler_startup () at sr_port/compiler_startup.c:130 #16 compile_source_file () at sr_unix/source_file.c:173 #17 op_zcompile () at sr_port/op_zcompile.c:57 #18 gtm_trigger_complink () at sr_unix/gtm_trigger.c:451 #19 gtm_trigger () at sr_unix/gtm_trigger.c:551 #20 gvtr_match_n_invoke () at sr_unix/gv_trigger.c:1683 #21 gvcst_put2 () at sr_port/gvcst_put.c:2806 #22 gvcst_put () at sr_port/gvcst_put.c:299 #23 op_gvput () at sr_port/op_gvput.c:79 #24 ydb_set_s () at sr_unix/ydb_set_s.c:137 #25 ydb_set_st () at sr_unix/ydb_set_st.c:42 #26 _cgo_d187034042ca_Cfunc_ydb_set_st () at cgo-gcc-prolog:170 #27 runtime.asmcgocall () at /usr/lib/go-1.11/src/runtime/asm_arm.s:617 ``` * The cause of the assert failure is a nested call to `gtm_malloc()` (frames 9 and 5 above). And the reason that nested call happened is because the initial allocation of the condition handler stack size of 5 was not enough when `sr_unix/ydb_stm_invoke_deferred_signal_handler.c` tried to do an ESTABLISH and add one more condition handler (at frame number 7). This is because the condition handler stack was already used up with the following handlers. ```gdb (gdb) p chnd[0].ch $14 = (void (*)()) 0xb62f4f70 (gdb) p chnd[1].ch $15 = (void (*)()) 0xb63b0f10 (gdb) p chnd[2].ch $16 = (void (*)()) 0xb67f1e0c (gdb) p chnd[3].ch $17 = (void (*)()) 0xb69c45e8 (gdb) p chnd[4].ch $18 = (void (*)()) 0xb6ce211c ``` * The initial condition handler stack size (controlled by the `CONDSTK_INITIAL_INCR` macro) is currently set to 5 (last changed from 2 to 5 as part of GT.M V6.3-000) for DEBUG builds and set to 8 for PRO/Release builds. * Due to YottaDB's use of SimpleAPI, this limit of 5 is clearly not enough (as shown by the above failure) so it is now being bumped to 8 for DEBUG and to 16 for PRO/Release builds (just to be safe). --- sr_unix/errorsp.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sr_unix/errorsp.h b/sr_unix/errorsp.h index 1b08abb2d..93386a4eb 100644 --- a/sr_unix/errorsp.h +++ b/sr_unix/errorsp.h @@ -3,7 +3,7 @@ * Copyright (c) 2001-2019 Fidelity National Information * * Services, Inc. and/or its subsidiaries. All rights reserved. * * * - * Copyright (c) 2017-2019 YottaDB LLC and/or its subsidiaries. * + * Copyright (c) 2017-2020 YottaDB LLC and/or its subsidiaries. * * All rights reserved. * * * * This source code contains the intellectual property * @@ -50,10 +50,13 @@ * in addition to the other handlers for each trigger frame, the maximums may need to be re-visited. */ #ifdef DEBUG -# define CONDSTK_INITIAL_INCR 5 /* Lower initial limit for DEBUG to exercise extensions. Note that values below 5 cause - * issues with nested malloc()s when using certain ydb_dbglvl values. */ +# define CONDSTK_INITIAL_INCR 8 /* Lower initial limit for DEBUG to exercise condition handler stack extensions. + * Note that even a value of 5 has been seen to cause issues with nested malloc()s + * (see commit message for details on the failure which showed this possibility). + * Hence setting this to 8 for DEBUG and bumping the initial limit to 16 for PRO builds. + */ #else -# define CONDSTK_INITIAL_INCR 8 /* Initial increment value used when expanding condition handler stack */ +# define CONDSTK_INITIAL_INCR 16 /* Initial increment value used when expanding condition handler stack */ #endif #define CONDSTK_MAX_INCR 128 /* Increment doubles each time expanded till hits this level */ #define CONDSTK_MAX_STACK 512 /* Actual max is approx 504 due to arithmetic progression */