ruby-changes:72051
From: Alan <ko1@a...>
Date: Sat, 4 Jun 2022 02:50:50 +0900 (JST)
Subject: [ruby-changes:72051] e4fe347302 (master): Prevent printing crash report in a loop
https://git.ruby-lang.org/ruby.git/commit/?id=e4fe347302 From e4fe3473027393aa084f4e6b2a01c29ec8281f99 Mon Sep 17 00:00:00 2001 From: Alan Wu <XrXr@u...> Date: Tue, 29 Mar 2022 13:38:55 -0400 Subject: Prevent printing crash report in a loop In the event that we are crashing due to a corrupt Ruby stack, we might re-enter rb_vm_bugreport() due to failed assertions in rb_backtrace_print_as_bugreport() or SDR(). In these cases we were printing the bug report ad infinitum with unbounded recusion. I seem to run into this every once in a while and the amount of log it prints out is pretty distracting. On CI environments it makes the log output unnecessarily big. Let's fix this. --- vm_dump.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/vm_dump.c b/vm_dump.c index 5c79e80352..9c7227b3d7 100644 --- a/vm_dump.c +++ b/vm_dump.c @@ -1021,6 +1021,17 @@ rb_vm_bugreport(const void *ctx) https://github.com/ruby/ruby/blob/trunk/vm_dump.c#L1021 } } + // Thread unsafe best effort attempt to stop printing the bug report in an + // infinite loop. Can happen with corrupt Ruby stack. + { + static bool crashing = false; + if (crashing) { + fprintf(stderr, "Crashed while printing bug report\n"); + return; + } + crashing = true; + } + #ifdef __linux__ # define PROC_MAPS_NAME "/proc/self/maps" #endif -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/