diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index e648792..a1621bf 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -553,9 +553,12 @@ errfinish(int dummy,...)
 	 *
 	 * But check for cancel/die interrupt first --- this is so that the user
 	 * can stop a query emitting tons of notice or warning messages, even if
-	 * it's in a loop that otherwise fails to check for interrupts.
+	 * it's in a loop that otherwise fails to check for interrupts. Before
+	 * returning to caller restore errno back as callers might take some action
+	 * based on errno.
 	 */
 	CHECK_FOR_INTERRUPTS();
+	errno = edata->saved_errno;
 }
 
 
