commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yaniv Kunda (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (EXEC-101) IOException when a process terminates before all buffered input bytes have been written
Date Tue, 26 Jan 2016 00:23:39 GMT

     [ https://issues.apache.org/jira/browse/EXEC-101?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Yaniv Kunda updated EXEC-101:
-----------------------------
    Attachment: Test.java

A class that recreates the problem on Java 8, resulting in the following exception:
{noformat}
Exception in thread "main" java.io.IOException: Stream Closed
	at java.io.FileOutputStream.writeBytes(Native Method)
	at java.io.FileOutputStream.write(FileOutputStream.java:326)
	at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
	at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
	at java.io.FilterOutputStream.close(FilterOutputStream.java:158)
	at org.apache.commons.exec.DefaultExecutor.closeProcessStreams(DefaultExecutor.java:306)
	at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:387)
	at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:166)
	at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:153)
	at Test.main(Test.java:19)
{noformat}

> IOException when a process terminates before all buffered input bytes have been written
> ---------------------------------------------------------------------------------------
>
>                 Key: EXEC-101
>                 URL: https://issues.apache.org/jira/browse/EXEC-101
>             Project: Commons Exec
>          Issue Type: Bug
>    Affects Versions: 1.3
>         Environment: Oracle JDK 1.8.0_72 x64 on MS Windows 10 Pro x64
>            Reporter: Yaniv Kunda
>         Attachments: Test.java
>
>
> I encountered a serious glitch when using commons-exec 1.3 with Java 8 - something that
didn't happen with previous Java versions (tested with Java 5 and 7).
> In order to feed a process' normal input stream, commons-exec uses Process.getOutputStream()
- which is normally a BufferedOutputStream, wrapping a FileOutputStream, pointing to the OS's
pseudo-file connected to the process' normal input stream.
> In Java 8, the process might terminate with the BufferedOutputStream still having unwritten
bytes in its buffer, while the underlying FileOutputStream gets automatically closed.
> DefaultExecutor always tries to close all of the process' streams, in closeProcessStreams()
- but because the process' BufferedOutputStream still has bytes in its buffers (count >
0), it first tries to flush it to the underlying FileOutputStreams, throwing an IOException
(Stream closed).
> The following scenario reproduces the problem:
> # Use DefaultExecutor to start a process which does not expect (or read) any bytes from
the normal input stream.
> # Feed the process (using PumpStreamHandler) a large amount of bytes.
> # Execute
> The change in behavior between Java 8 and previous versions actually lies within FilterOutputStream,
which contains the implementation of close() used by BufferOutputStream - before Java 8, the
implementation would ignore (swallow) any exception cause by the call to flush() in close()
- in Java 8, the exception propagates.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message