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

[JBPM-9334] Process execution stuck at ExecWorkItemHandler node if co… #147

Merged
merged 18 commits into from Oct 14, 2020

Conversation

abhijithumbe
Copy link
Contributor

…mmand is long running.

Thank you for submitting this pull request

JIRA: (please edit the JIRA link if it exists)

link

referenced Pull Requests: (please edit the URLs of referenced pullrequests if they exist)

  • paste the link(s) from GitHub here
  • link 2
  • link 3 etc.
How to retest a PR or trigger a specific build:

* a pull request please add comment: Jenkins retest this
 
* a full downstream build please add comment: Jenkins run fdb
  
* a compile downstream build please  add comment: Jenkins run cdb

* a full production downstream build please add comment: Jenkins execute product fdb

* an upstream build please add comment: Jenkins run upstream

@kie-ci
Copy link

kie-ci commented Sep 10, 2020

Can one of the admins verify this PR? Comment with 'ok to test' to start the build.

9 similar comments
@kie-ci
Copy link

kie-ci commented Sep 10, 2020

Can one of the admins verify this PR? Comment with 'ok to test' to start the build.

@kie-ci
Copy link

kie-ci commented Sep 10, 2020

Can one of the admins verify this PR? Comment with 'ok to test' to start the build.

@kie-ci
Copy link

kie-ci commented Sep 10, 2020

Can one of the admins verify this PR? Comment with 'ok to test' to start the build.

@kie-ci
Copy link

kie-ci commented Sep 10, 2020

Can one of the admins verify this PR? Comment with 'ok to test' to start the build.

@kie-ci
Copy link

kie-ci commented Sep 10, 2020

Can one of the admins verify this PR? Comment with 'ok to test' to start the build.

@kie-ci
Copy link

kie-ci commented Sep 10, 2020

Can one of the admins verify this PR? Comment with 'ok to test' to start the build.

@kie-ci
Copy link

kie-ci commented Sep 10, 2020

Can one of the admins verify this PR? Comment with 'ok to test' to start the build.

@kie-ci
Copy link

kie-ci commented Sep 10, 2020

Can one of the admins verify this PR? Comment with 'ok to test' to start the build.

@kie-ci
Copy link

kie-ci commented Sep 10, 2020

Can one of the admins verify this PR? Comment with 'ok to test' to start the build.

@krisv
Copy link
Member

krisv commented Sep 10, 2020

ok to test

@@ -43,7 +47,8 @@
icon = "Exec.png",
parameters = {
@WidParameter(name = "Command", required = true),
@WidParameter(name = "Arguments", runtimeType = "java.util.List")
@WidParameter(name = "Arguments", runtimeType = "java.util.List"),
@WidParameter(name = "CommandExecutionTimeout", runtimeType = "java.lang.String")
Copy link
Member

@tsurdilo tsurdilo Sep 10, 2020

Choose a reason for hiding this comment

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

Just "Timeout" would be simpler here, but not a big deal at all.
Also specifying the expected time value (seconds, minutes, hours) would be nice.
So if you expect seconds you could call it "TimeoutInSeconds" for example.

@@ -104,6 +131,10 @@ public void abortWorkItem(WorkItem workItem,
WorkItemManager manager) {
// Do nothing, this work item cannot be aborted
}

public void SetDefaultTimeoutInSeconds(long defaultTimeoutInSeconds) {
Copy link
Member

Choose a reason for hiding this comment

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

method name should start with lower case letter.

String commandExecutionTimeout = (String) workItem.getParameter("CommandExecutionTimeout");

if (commandExecutionTimeout ==null) {
this.SetDefaultTimeoutInSeconds(4L);
Copy link
Member

Choose a reason for hiding this comment

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

you can just initialize defaultTimeoutInSeconds up front with this value then you dont need to do it here.

@@ -71,6 +78,13 @@ public void executeWorkItem(WorkItem workItem,

String command = (String) workItem.getParameter("Command");
List<String> arguments = (List<String>) workItem.getParameter("Arguments");
String commandExecutionTimeout = (String) workItem.getParameter("CommandExecutionTimeout");

if (commandExecutionTimeout ==null) {
Copy link
Member

Choose a reason for hiding this comment

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

commandExecutionTimeout is a string, so you should also check if its empty, and if it actually is a time.
Also if you are expecting the timeout to be in seconds, then the parameter should prob change to make sure thats clear, for example "TimeoutInSeconds" or something that is clear to readers what is expected.

You can also look into using ISO 8601 if possible to describe the time, for example "PT2M" for "2 minutes" etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -82,11 +96,24 @@ public void executeWorkItem(WorkItem workItem,

parsedCommandStr = commandLine.toString();

ExecuteWatchdog watchdog = new ExecuteWatchdog(java.time.Duration.ofSeconds(defaultTimeoutInSeconds).toMillis());
Copy link
Member

Choose a reason for hiding this comment

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

use import rather than full path (java.time.Duration)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

} catch (IOException e) {
if (watchdog.killedProcess()) {
logger.debug("A timeout occured after "+java.time.Duration.ofSeconds(defaultTimeoutInSeconds).toMillis()+"ms while executing a command "+parsedCommandStr.replace(",", ""));
results.put(RESULT, outputStream.toString());
Copy link
Member

@tsurdilo tsurdilo Sep 10, 2020

Choose a reason for hiding this comment

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

If there was a timeout error / exception then I assume outputstream is empty ? wonder if you should return a default value or none at all here. Consider also how will the process know that there the execution of this command failed? Maybe a specific return value can be used that lets the rest of the process be able to reason over a possible failure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

outputstream do have a partial response for ping command. But sending partial response is not good idea. I have added failure message in result object in case of timeout and also added logger to log error.

@@ -85,6 +85,35 @@ public void testExecCommandWithArguments() throws Exception {
assertNotNull(result);
assertTrue(result.contains("java version") || result.contains("jdk version"));
}

@Test(timeout=6000)
Copy link
Member

Choose a reason for hiding this comment

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

I dont understand how this test method actually tests the code that you have added in the handler :) please explain. Need a test that actually times out to test that the timeout is actually handled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this test I am executing ping command, when we execute ping command from the terminal we have to manually terminate the command. Here junit test will wait for 5 seconds to complete its executiom. If command execution didnt terminated/completed within 5 secs, test will keep running for its completion. So to terminate junit test added 6 seconds timeout for test.

@tsurdilo
Copy link
Member

Thanks for the PR! Left some comments. Also for this PR and last one you did I wonder if the code could be formatted in your editor?

@abhijithumbe
Copy link
Contributor Author

Seems issue with IDE code format. Do we have any same code to includude in IDE formattter/code style ?
kindly review the new commit c5cebe6

@tsurdilo
Copy link
Member

@abhijithumbe One small thing I noticed is that in #145 it also has a timeout parameter that expects milliseconds and called "TimeoutInMillis" - do you think we could align the two so they are the same? Probably little confusing that one workitem expects milliseconds and the other seconds. WDYT?

@tsurdilo
Copy link
Member

Thanks for the contribution and doing all the updates!
This looks good to me, the only thing is formatting, I think you can just follow this page for optaplanner :) - https://github.com/kiegroup/optaplanner/blob/master/ide-configuration/ide-configuration.adoc

@tsurdilo
Copy link
Member

Jenkins retest this

@abhijithumbe
Copy link
Contributor Author

@abhijithumbe One small thing I noticed is that in #145 it also has a timeout parameter that expects milliseconds and called "TimeoutInMillis" - do you think we could align the two so they are the same? Probably little confusing that one workitem expects milliseconds and the other seconds. WDYT?

updated WIH to accept timeout in milliseconds.

@abhijithumbe
Copy link
Contributor Author

Thanks for the contribution and doing all the updates!
This looks good to me, the only thing is formatting, I think you can just follow this page for optaplanner :) - https://github.com/kiegroup/optaplanner/blob/master/ide-configuration/ide-configuration.adoc

Thank you for all your help :) Now code should be in the required format. Kindly review latest commit

@tsurdilo
Copy link
Member

@abhijithumbe LGTM

@MarianMacik same here- do we need a QE review or can merge ?

@tsurdilo
Copy link
Member

Jenkins retest please

@abhijithumbe
Copy link
Contributor Author

@abhijithumbe LGTM

@MarianMacik same here- do we need a QE review or can merge ?

@MarianMacik can you please share thoughts on this ?

Copy link
Member

@MarianMacik MarianMacik left a comment

Choose a reason for hiding this comment

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

Just formatting. Otherwise looks good. Thanks a lot for the improvement!

@abhijithumbe
Copy link
Contributor Author

@MarianMacik Could you please review?

@MarianMacik MarianMacik merged commit 0256e21 into kiegroup:master Oct 14, 2020
matejonnet pushed a commit to matejonnet/jbpm-work-items that referenced this pull request Dec 1, 2020
kiegroup#147)

* [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running.

* [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running

* [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running

* [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running

* [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running

* [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running

* [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running

* [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running

* [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running

* [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running

* [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running

* [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running

* [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running

* [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running

* [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running

* [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running

* [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running

* [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants