Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -527,16 +527,7 @@ public void stop()

synchronized (tasks) {
for (ForkingTaskRunnerWorkItem taskWorkItem : tasks.values()) {
if (taskWorkItem.processHolder != null) {
log.info("Closing output stream to task[%s].", taskWorkItem.getTask().getId());
try {
taskWorkItem.processHolder.process.getOutputStream().close();
}
catch (Exception e) {
log.warn(e, "Failed to close stdout to task[%s]. Destroying task.", taskWorkItem.getTask().getId());
taskWorkItem.processHolder.process.destroy();
}
}
shutdownTaskProcess(taskWorkItem);
}
}

Expand Down Expand Up @@ -593,12 +584,8 @@ public void shutdown(final String taskid, String reason)
}

taskInfo.shutdown = true;
}

if (taskInfo.processHolder != null) {
// Will trigger normal failure mechanisms due to process exit
log.info("Killing process for task: %s", taskid);
taskInfo.processHolder.process.destroy();
shutdownTaskProcess(taskInfo);
}
}

Expand Down Expand Up @@ -694,8 +681,10 @@ public InputStream openStream() throws IOException
);
}

// Save running tasks to a file, so they can potentially be restored on next startup. Suppresses exceptions that
// occur while saving.
/**
* Save running tasks to a file, so they can potentially be restored on next startup. Suppresses exceptions that occur
* while saving.
*/
@GuardedBy("tasks")
private void saveRunningTasks()
{
Expand All @@ -714,6 +703,25 @@ private void saveRunningTasks()
}
}

/**
* Close task output stream (input stream of process) sending EOF telling process to terminate, destroying the process
* if an exception is encountered.
*/
private void shutdownTaskProcess(ForkingTaskRunnerWorkItem taskInfo)
Copy link
Copy Markdown
Contributor

@jihoonson jihoonson Jul 15, 2019

Choose a reason for hiding this comment

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

Would you add a comment like "this method triggers lifecycle.stop()"?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It sort of seems like a misleading comment, since it doesn't call that directly, it's just closing the stream of the forked task and destroying it if that encounters an exception. Also since I am not entirely sure that lifecycle stop wasn't being called previously...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That said, I agree it probably needs some sort of javadoc/comment, i'll see what I can come up with

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

added javadoc

{
if (taskInfo.processHolder != null) {
// Will trigger normal failure mechanisms due to process exit
log.info("Closing output stream to task[%s].", taskInfo.getTask().getId());
try {
taskInfo.processHolder.process.getOutputStream().close();
}
catch (Exception e) {
log.warn(e, "Failed to close stdout to task[%s]. Destroying task.", taskInfo.getTask().getId());
taskInfo.processHolder.process.destroy();
}
}
}

private File getRestoreFile()
{
return new File(taskConfig.getBaseTaskDir(), TASK_RESTORE_FILENAME);
Expand Down