Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPCC-33031 Add the option to terminate a child process gracefully #19317

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deployment/deploy/DeployTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,7 @@ class CDeployTask : public CInterface, implements IDeployTask
{
retcode = 5;
errbuf.clear().append("Invalid or missing key passphrase. ");
pipe->abort();
pipe->abort(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this/almost all should be graceful too really, but to avoid potential deadlock from misbehaving child, it would be good if abort fired a SIGKILL after a given period of grace time..

return retcode;
}

Expand Down
4 changes: 2 additions & 2 deletions ecl/eclccserver/eclccserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class AbortWaiter : public Thread
ForEachItemIn(idx, pipes)
{
IPipeProcess *pipe = pipes.item(idx);
pipe->abort();
pipe->abort(true);
}
break;
}
Expand All @@ -187,7 +187,7 @@ class AbortWaiter : public Thread
CriticalBlock b(crit);
pipes.append(LINK(pipe));
if (timedOut)
pipe->abort();
pipe->abort(true);
}
void removePipe(IPipeProcess *pipe)
{
Expand Down
9 changes: 5 additions & 4 deletions system/jlib/jthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,7 @@ class CWindowsPipeProcess: implements IPipeProcess, public CInterface
doCloseError();
}

void abort()
void abort(bool gracefull) override
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trivial: and add 'virtual' ?

{
CriticalBlock block(sect);
if (pipeProcess != (HANDLE)-1) {
Expand Down Expand Up @@ -2416,7 +2416,7 @@ protected: friend class PipeWriterThread;
}
}

void abort()
void abort(bool graceful) override
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trivial: and add 'virtual' ?

{
CriticalBlock block(sect);
aborted = true;
Expand All @@ -2432,10 +2432,11 @@ protected: friend class PipeWriterThread;
if (pipeProcess != (HANDLE)-1) {
if (title.length())
PROGLOG("%s: Forcibly killing pipe process %d",title.get(),pipeProcess);
int signalToSend = graceful ? SIGTERM : SIGKILL;
if (newProcessGroup)
::kill(-pipeProcess,SIGKILL);
::kill(-pipeProcess,signalToSend);
else
::kill(pipeProcess,SIGKILL); // if this doesn't kill it we are in trouble
::kill(pipeProcess,signalToSend); // if this doesn't kill it we are in trouble
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if graceful, should there be a grace period, which if exceeded fires a SIGKILL anyway..?

CriticalUnblock unblock(sect);
wait();
}
Expand Down
2 changes: 1 addition & 1 deletion system/jlib/jthread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ interface IPipeProcess: extends IInterface
virtual void closeInput() = 0; // indicate finished input to pipe
virtual void closeOutput() = 0; // indicate finished reading from pipe (generally called automatically)
virtual void closeError() = 0; // indicate finished reading from pipe stderr
virtual void abort() = 0;
virtual void abort(bool gracefull) = 0; // graceful=true allows the child process to clean up.
virtual void notifyTerminated(HANDLE pid,unsigned retcode) = 0; // internal
virtual HANDLE getProcessHandle() = 0; // used to auto kill
virtual void setenv(const char *var, const char *value) = 0; // Set a value to be passed in the called process environment
Expand Down
2 changes: 1 addition & 1 deletion thorlcr/activities/piperead/thprslave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class CPipeSlaveBase : public CSlaveActivity
void abortPipe()
{
unregisterSelfDestructChildProcess(pipe->getProcessHandle());
pipe->abort();
pipe->abort(false);
}

public:
Expand Down
2 changes: 1 addition & 1 deletion thorlcr/activities/pipewrite/thpwslave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CPipeWriteSlaveActivity : public ProcessSlaveActivity
if (pipeOpen)
{
unregisterSelfDestructChildProcess(pipe->getProcessHandle());
pipe->abort();
pipe->abort(false);
}
ProcessSlaveActivity::abort();
}
Expand Down
Loading