未验证 提交 70f55c3d 编写于 作者: M Ming LI 提交者: GitHub

Need to close pipe files even if COPY PROGRAME already exit (#4585)

Need to close pipe files even if COPY PROGRAME already exit before parent process ask child process to exit, otherwise it will lead file description leak in a long time running.
上级 28849ee7
...@@ -777,7 +777,7 @@ read_err_msg(int fid, StringInfo sinfo) ...@@ -777,7 +777,7 @@ read_err_msg(int fid, StringInfo sinfo)
int int
pclose_with_stderr(int pid, int *pipes, StringInfo sinfo) pclose_with_stderr(int pid, int *pipes, StringInfo sinfo)
{ {
int status; int status = 0;
/* close the data pipe. we can now read from error pipe without being blocked */ /* close the data pipe. we can now read from error pipe without being blocked */
close(pipes[EXEC_DATA_P]); close(pipes[EXEC_DATA_P]);
...@@ -786,11 +786,14 @@ pclose_with_stderr(int pid, int *pipes, StringInfo sinfo) ...@@ -786,11 +786,14 @@ pclose_with_stderr(int pid, int *pipes, StringInfo sinfo)
close(pipes[EXEC_ERR_P]); close(pipes[EXEC_ERR_P]);
#ifndef WIN32 if (kill(pid, 0) == 0) /* process exists */
{
#ifndef WIN32
waitpid(pid, &status, 0); waitpid(pid, &status, 0);
#else #else
status = -1; status = -1;
#endif #endif
}
return status; return status;
} }
......
...@@ -8204,10 +8204,7 @@ close_program_pipes(CopyState cstate, bool ifThrow) ...@@ -8204,10 +8204,7 @@ close_program_pipes(CopyState cstate, bool ifThrow)
return; return;
} }
if (kill(cstate->program_pipes->pid, 0) == 0) /* process exists */
{
ret = pclose_with_stderr(cstate->program_pipes->pid, cstate->program_pipes->pipes, &sinfo); ret = pclose_with_stderr(cstate->program_pipes->pid, cstate->program_pipes->pipes, &sinfo);
}
if (ret == 0 || !ifThrow) if (ret == 0 || !ifThrow)
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册