Fix worker crash when coordinator disconnects

cmake_branch_point
Brian Cloutier 2018-04-10 23:36:02 +00:00 committed by Brian Cloutier
parent 73e1d81bb3
commit 667280650d
1 changed files with 27 additions and 16 deletions

View File

@ -48,31 +48,42 @@ RedirectCopyDataToRegularFile(const char *filename)
fileDesc = FileOpenForTransmit(filename, fileFlags, fileMode); fileDesc = FileOpenForTransmit(filename, fileFlags, fileMode);
SendCopyInStart(); PG_TRY();
copyDone = ReceiveCopyData(copyData);
while (!copyDone)
{ {
/* if received data has contents, append to regular file */
if (copyData->len > 0) SendCopyInStart();
copyDone = ReceiveCopyData(copyData);
while (!copyDone)
{ {
/* if received data has contents, append to regular file */
if (copyData->len > 0)
{
#if (PG_VERSION_NUM >= 100000) #if (PG_VERSION_NUM >= 100000)
int appended = FileWrite(fileDesc, copyData->data, copyData->len, int appended = FileWrite(fileDesc, copyData->data, copyData->len,
PG_WAIT_IO); PG_WAIT_IO);
#else #else
int appended = FileWrite(fileDesc, copyData->data, copyData->len); int appended = FileWrite(fileDesc, copyData->data, copyData->len);
#endif #endif
if (appended != copyData->len) if (appended != copyData->len)
{ {
ereport(ERROR, (errcode_for_file_access(), ereport(ERROR, (errcode_for_file_access(),
errmsg("could not append to received file: %m"))); errmsg("could not append to received file: %m")));
}
} }
}
resetStringInfo(copyData); resetStringInfo(copyData);
copyDone = ReceiveCopyData(copyData); copyDone = ReceiveCopyData(copyData);
}
} }
PG_CATCH();
{
FreeStringInfo(copyData);
FileClose(fileDesc);
PG_RE_THROW();
}
PG_END_TRY();
FreeStringInfo(copyData); FreeStringInfo(copyData);
FileClose(fileDesc); FileClose(fileDesc);