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

Uncaught exception print in stderr when timeout #36

Closed
javierfreire opened this issue Aug 22, 2022 · 1 comment
Closed

Uncaught exception print in stderr when timeout #36

javierfreire opened this issue Aug 22, 2022 · 1 comment

Comments

@javierfreire
Copy link

Describe the bug

When a timeout occurs, the behavior is correct but, sometimes, a race condition happens and an unhandled exception is thrown.

To Reproduce

public class TimeoutTest {

    public static void main(String[] args) {
        ProcBuilder builder = new ProcBuilder("bash",  "-i", "-c", "echo hello").withTimeoutMillis(1);

        try {
            builder.run();
        } catch (TimeoutException ex) {
            //OK
        }
    }
}

Expected behavior

No uncaught exception should be printed in stderr.

Actual Behaviour

These traces are printed by stderr

Exception in thread "Thread-1" java.lang.RuntimeException: ${END}
	at org.buildobjects.process.Proc.dispatch(Proc.java:168)
	at org.buildobjects.process.ByteArrayConsumptionThread$1.run(ByteArrayConsumptionThread.java:36)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.InterruptedException
	at java.base/java.util.concurrent.locks.ReentrantLock$Sync.lockInterruptibly(ReentrantLock.java:159)
	at java.base/java.util.concurrent.locks.ReentrantLock.lockInterruptibly(ReentrantLock.java:372)
	at java.base/java.util.concurrent.LinkedBlockingQueue.put(LinkedBlockingQueue.java:332)
	at org.buildobjects.process.Proc.dispatch(Proc.java:166)
	... 2 more
Exception in thread "Thread-0" java.lang.RuntimeException: ${END}
	at org.buildobjects.process.Proc.dispatch(Proc.java:168)
	at org.buildobjects.process.StreamCopyConsumptionThread$1.run(StreamCopyConsumptionThread.java:30)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.InterruptedException
	at java.base/java.util.concurrent.locks.ReentrantLock$Sync.lockInterruptibly(ReentrantLock.java:159)
	at java.base/java.util.concurrent.locks.ReentrantLock.lockInterruptibly(ReentrantLock.java:372)
	at java.base/java.util.concurrent.LinkedBlockingQueue.put(LinkedBlockingQueue.java:332)
	at org.buildobjects.process.Proc.dispatch(Proc.java:166)
	... 2 more

I didn't expect any uncaught exception.

Context

I did use Ubuntu.

@fleipold
Copy link
Owner

Thank you @javierfreire for finding and fixing this issue. I'll review your PR shortly.

fleipold added a commit that referenced this issue Aug 25, 2022
Fix #36; Avoid uncaught exception on timeout
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

No branches or pull requests

2 participants