This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch: close I/O channels when a process ends


Andrew Haley wrote:
> David Daney writes:
>  > Tom Tromey wrote:
>  > >>>>>>"Andrew" == Andrew Haley <aph@redhat.com> writes:
>  > > 
>  > > 
>  > > Andrew> I ran out of file handles.  Was there any reason we weren't
>  > > Andrew> closing the files in Process.waitFor?
>  > > 
>  > > It probably isn't valid to do this.
>  > > Couldn't there still be data in the OS' pipe buffer?
>  > > 
>  > > Tom
>  > 
>  > My patch that is waiting for approval is an almost total rewrite of
>  > natPosixProcess, so would replace this.  However it would not solve the
>  > problem either.
>  > 
>  > I think that the place to fix this is in
>  > FileInputStream/FileChannelImpl.  When you get end-of-file when reading
>  > a pipe/file, you should close the descriptor there.
> 
> But we can still close the output channels here, can we?
> 

Tom Tromey and I are saying that it might break something.  There is
guarantee that what ever is reading from the inputStream and errorStream
will have received all of the data before the thread that does the
waitFor() closes the streams.

I personally do not have code that does waitFor() before receiving EOF
on the inputStream, so it would not break things for me.  However I
think that we have to assure that when a Process terminates cleanly we
can read all the data and get an EOF indication.

With your change if the waitFor() happens on a different thread, it is
possible to miss some of the data and get an IOException instead.
Further more it would depend on thread scheduling as to what would
happen.  I think non-deterministic behavior like this should be avoided
when possible.

David Daney.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]