Fix elog.c to avoid infinite recursion (leading to backend crash) when
authorTom Lane <[email protected]>
Sat, 21 Jul 2007 22:12:11 +0000 (22:12 +0000)
committerTom Lane <[email protected]>
Sat, 21 Jul 2007 22:12:11 +0000 (22:12 +0000)
log_min_error_statement is active and there is some problem in logging the
current query string; for example, that it's too long to include in the log
message without running out of memory.  This problem has existed since the
log_min_error_statement feature was introduced.  No doubt the reason it
wasn't detected long ago is that 8.2 is the first release that defaults
log_min_error_statement to less than PANIC level.
Per report from Bill Moran.

src/backend/utils/error/elog.c

index 951933215cc6b41fe536f8cd5cc5889f16dd84c6..3f3606cd329012316e39dec88db903521ac6871c 100644 (file)
@@ -261,10 +261,15 @@ errstart(int elevel, const char *filename, int lineno,
 
                /*
                 * If we recurse more than once, the problem might be something broken
-                * in a context traceback routine.      Abandon them too.
+                * in a context traceback routine.  Abandon them too.  We also
+                * abandon attempting to print the error statement (which, if long,
+                * could itself be the source of the recursive failure).
                 */
                if (recursion_depth > 2)
+               {
                        error_context_stack = NULL;
+                       debug_query_string = NULL;
+               }
        }
        if (++errordata_stack_depth >= ERRORDATA_STACK_SIZE)
        {