You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Oliver Waeldrich (JIRA)" <ji...@apache.org> on 2018/03/06 10:09:00 UTC

[jira] [Commented] (EXEC-65) Watchdog can't destroy 'sudo' and 'sleep'

    [ https://issues.apache.org/jira/browse/EXEC-65?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16387560#comment-16387560 ] 

Oliver Waeldrich commented on EXEC-65:
--------------------------------------

I experienced same problem on Ubuntu. However, it seems that using a noop ExecuteStreamHandler at least allows one to terminate the process. In my case, it took about 45 seconds until the process was terminated. When using the PumpStreamHandler, the process was not terminated at all.

The underlying problems seems to be the StreamPumper, which continously reads from process stdout, without checking if bytes are available. This seems to prevent termination of the process, which in turn might also be a bug in the jdk. However, to fix this issue, StreamPumper should check if bytes are available before reading.

> Watchdog can't destroy 'sudo' and 'sleep'
> -----------------------------------------
>
>                 Key: EXEC-65
>                 URL: https://issues.apache.org/jira/browse/EXEC-65
>             Project: Commons Exec
>          Issue Type: Bug
>    Affects Versions: 1.1
>         Environment: RedHat Enterprise Linux 64bit, JDK 1.6.0_25 64bit.
> {code}
> $ uname -a
> Linux demo-vrs1-happdb1.lts.stgt.vrs.cust.disy.net 2.6.9-42.ELsmp #1 SMP Wed Jul 12 23:27:17 EDT 2006 i686 i686 i386 GNU/Linux
> {code}
> {code}
> $ java -version
> java version "1.6.0_25"
> Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
> Java HotSpot(TM) Server VM (build 20.0-b11, mixed mode)
> {code}
>            Reporter: Rusi Filipov
>            Assignee: Siegfried Goeschl
>            Priority: Critical
>         Attachments: EXEC_65.patch
>
>
> I want to run a command from a shell script with make sure the process will be destroyed after a timeout, especially if it asks for user input or contains sleep commands.
> {code:title=Java}
> DefaultExecutor executor = new DefaultExecutor();
> executor.setStreamHandler(new PumpStreamHandler(System.out, System.err));
> ExecuteWatchdog watchDog = new ExecuteWatchdog(3000);
> executor.setWatchdog(watchDog);
> CommandLine command = new CommandLine("./client.sh");
> int exitValue = executor.execute(command);
> System.out.println(exitValue);
> {code}
> I run this code on the server like this:
> {code}
> java -cp .:commons-exec-1.1.jar App
> {code}
> *Problem 1.* I want to run {{sudo}} in order to execute a script as a different user:
> {code:title=client.sh}
> #!/bin/bash
> sudo -u occ02 /apps/occ02/catalina_base/bin/restart-occ.sh
> {code}
> In case of a misconfiguration of {{/etc/sudoers}} this prompts me for a password.
> {code}
> Password:
> {code}
> And terminates only after about 5 minutes, not 3 seconds:
> {code}
> Exception in thread "main" org.apache.commons.exec.ExecuteException: Process exited with an error: 143 (Exit value: 143)
>         at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:377)
>         at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:160)
>         at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:147)
>         at App.destroy2(App.java:51)
>         at App.main(App.java:21)
> {code}
> Only if I use the {{sudo -S ...}} the process is killed after about 4 seconds:
> {code}
> Password:
> Exception in thread "main" org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
>         at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:377)
>         at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:160)
>         at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:147)
>         at App.destroy2(App.java:51)
>         at App.main(App.java:21)
> {code}
> *Problem 2.* I want to prevent a too long {{sleep}}:
> {code:title=client.sh}
> #!/bin/bash
> sleep 900
> {code}
> The Process just hangs! After 15 minutes the process terminates with this error:
> {code}
> Exception in thread "main" org.apache.commons.exec.ExecuteException: Process exited with an error: 143 (Exit value: 143)
>         at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:377)
>         at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:160)
>         at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:147)
>         at App.destroy2(App.java:51)
>         at App.main(App.java:21)
> {code}
> If I run the {{sleep}} command directly from within Java without the shell-script, the process is destroyed on time:
> {code}
> DefaultExecutor executor = new DefaultExecutor();
> executor.setStreamHandler(new PumpStreamHandler(System.out, System.err));
> ExecuteWatchdog watchDog = new ExecuteWatchdog(3000);
> executor.setWatchdog(watchDog);
> CommandLine command = new CommandLine("sleep");
> command.addArgument("900");
> int exitValue = executor.execute(command);
> System.out.println(exitValue);
> {code}
> {code}
> Exception in thread "main" org.apache.commons.exec.ExecuteException: Process exited with an error: 143 (Exit value: 143)
>         at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:377)
>         at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:160)
>         at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:147)
>         at App.destroy4(App.java:67)
>         at App.main(App.java:23)
> {code}
> The problems were not visible when I tested on my development machine with Windows 7 64bit and JDK 1.6.0_25, 64bit. But now these issues are a serious barrier for using commons-exec in production.
> Btw, with the {{ProcessBuilder}} from the JDK the process is destroyed in both cases:
> {code}
> ProcessBuilder builder = new ProcessBuilder("./client.sh");
> Process process = builder.start();
> Thread.sleep(3000);
> process.destroy();
> {code}
> Best regards,
> Rusi



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)