Don't return in PG_TRY() block when cancellations happen in WaitForConnections(). (#1923)

We shouldn't return in middle of a PG_TRY() block because if we do, we won't reset PG_exception_stack, and later when a re-throw tries to jump to the jump-point which was active in this PG_TRY() block, it seg-faults.

We used to return in middle of PG_TRY() block in WaitForConnections() where we checked for cancellations. Whenever cancellations were caught here, Citus crashed. And example was reported by @onderkalaci at #1903.
pull/1928/head
Hadi Moshayedi 2018-01-03 09:54:03 -05:00 committed by GitHub
parent 8f69973411
commit 5d7c52ffa6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 3 deletions

View File

@ -781,6 +781,7 @@ WaitForAllConnections(List *connectionList, bool raiseInterrupts)
while (pendingConnectionsStartIndex < totalConnectionCount)
{
bool cancellationReceived = false;
int eventIndex = 0;
int eventCount = 0;
long timeout = -1;
@ -837,9 +838,13 @@ WaitForAllConnections(List *connectionList, bool raiseInterrupts)
if (InterruptHoldoffCount > 0 && (QueryCancelPending ||
ProcDiePending))
{
/* return immediately in case of cancellation */
FreeWaitEventSet(waitEventSet);
return;
/*
* Break out of event loop immediately in case of cancellation.
* We cannot use "return" here inside a PG_TRY() block since
* then the exception stack won't be reset.
*/
cancellationReceived = true;
break;
}
continue;
@ -905,6 +910,11 @@ WaitForAllConnections(List *connectionList, bool raiseInterrupts)
}
}
if (cancellationReceived)
{
break;
}
/* move non-ready connections to the back of the array */
for (connectionIndex = pendingConnectionsStartIndex;
connectionIndex < totalConnectionCount; connectionIndex++)