Reconsider context for calling callback functions --- original idea
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 3 Aug 2003 23:44:44 +0000 (23:44 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 3 Aug 2003 23:44:44 +0000 (23:44 +0000)
that they aren't part of error processing is clearly faulty.

src/backend/utils/error/elog.c

index 6c6acd4a7eb8739d4213ad9aac40540a9cc51af1..80938e13829f10b505e6b489b2085b0780c96026 100644 (file)
@@ -318,12 +318,19 @@ errfinish(int dummy, ...)
        MemoryContext oldcontext;
        ErrorContextCallback *econtext;
 
+       recursion_depth++;
        CHECK_STACK_DEPTH();
 
        /*
-        * Call any context callback functions.  We can treat ereports occuring
-        * in callback functions as re-entrant rather than recursive case, so
-        * don't increment recursion_depth yet.
+        * Do processing in ErrorContext, which we hope has enough reserved space
+        * to report an error.
+        */
+       oldcontext = MemoryContextSwitchTo(ErrorContext);
+
+       /*
+        * Call any context callback functions.  Errors occurring in callback
+        * functions will be treated as recursive errors --- this ensures we
+        * will avoid infinite recursion (see errstart).
         */
        for (econtext = error_context_stack;
                 econtext != NULL;
@@ -332,15 +339,6 @@ errfinish(int dummy, ...)
                (*econtext->callback) (econtext->arg);
        }
 
-       /* Now we are ready to process the error. */
-       recursion_depth++;
-
-       /*
-        * Do processing in ErrorContext, which we hope has enough reserved space
-        * to report an error.
-        */
-       oldcontext = MemoryContextSwitchTo(ErrorContext);
-
        /* Send to server log, if enabled */
        if (edata->output_to_server)
                send_message_to_server_log(edata);