Skip to content

Commit 3fbebea

Browse files
gongxun0928my-ship-it
authored andcommitted
fix coredump in interconnect_abort_callback
In the exception handling logic of interconnect_abort_callback, we invoked elog(ERROR) without properly handling the PostgreSQL exception using PG_TRY/PG_CATCH. This oversight could lead to the process exiting abnormally. When an uncaught PostgreSQL exception occurs in the exception handling function registered via RegisterResourceReleaseCallback, the exception callback function is recursively invoked. This recursion may eventually cause the errordata stack to exceed its allocated size, triggering an ERROR(PANIC) and causing the process to terminate abnormally.
1 parent fb86851 commit 3fbebea

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

contrib/interconnect/tcp/ic_tcp.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1895,6 +1895,22 @@ SetupTCPInterconnect(EState *estate)
18951895
estate->es_interconnect_is_setup = true;
18961896
} /* SetupTCPInterconnect */
18971897

1898+
static void TeardownInterconnectTCPCallbck(ChunkTransportState *transportStates,
1899+
bool hasErrors)
1900+
{
1901+
PG_TRY();
1902+
{
1903+
TeardownTCPInterconnect(transportStates, hasErrors);
1904+
}
1905+
PG_CATCH();
1906+
{
1907+
char *error_message = elog_message();
1908+
elog(WARNING, "TeardownInterconnectTCPCallbck: failed to teardown interconnect, error: %s",
1909+
error_message ? error_message : "unknown error");
1910+
}
1911+
PG_END_TRY();
1912+
}
1913+
18981914
void
18991915
SetupInterconnectTCP(EState *estate)
19001916
{
@@ -1910,7 +1926,7 @@ SetupInterconnectTCP(EState *estate)
19101926
elog(ERROR, "SetupInterconnectTCP: no slice table ?");
19111927
}
19121928

1913-
h = allocate_interconnect_handle(TeardownInterconnectTCP);
1929+
h = allocate_interconnect_handle(TeardownInterconnectTCPCallbck);
19141930

19151931
Assert(InterconnectContext != NULL);
19161932
oldContext = MemoryContextSwitchTo(InterconnectContext);

0 commit comments

Comments
 (0)