Repository navigation
fix(io): close the host stdout or stderr when Java closes descriptor 1 or 2 #82
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cf96442
fix(io): close the host stdout or stderr when Java closes descriptor …
Project516 1074476
test(jtreg): put LotsOfOutput back in passing.txt
Project516 6f6cbe5
fix(io): use the platform's null device and close on a stream error too
Project516 fa4fb99
fix(io): close the host stream after its pending writes and test clos…
Project516 d56b380
fix(io): put the null device on descriptor 1 or 2 even when a lower o…
Project516 fecdb59
fix(io): close at once when the host stream has already ended
Project516 5906aa4
fix(io): close the host descriptor only on the main thread
Project516 e64b4b0
fix(io): also close when the host stream closes without an error
Project516 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import java.io.File; | ||
| import java.io.FileDescriptor; | ||
| import java.io.FileOutputStream; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.io.PrintStream; | ||
| import java.util.Arrays; | ||
|
|
||
| // A child that closes System.out (or System.err) ends that stream at once: the parent reads it to | ||
| // the end first, while the child writes more to the other stream than a pipe holds. | ||
| public class CloseStdout { | ||
| public static void main(String[] args) throws Exception { | ||
| if (args.length > 0) { | ||
| boolean out = args[0].equals("out"); | ||
| PrintStream closing = out ? System.out : System.err, other = out ? System.err : System.out; | ||
| closing.print("before close"); | ||
| closing.close(); | ||
| byte[] line = new byte[1023]; | ||
| Arrays.fill(line, (byte) 'e'); | ||
| for (int i = 0; i < 1024; i++) { | ||
| other.write(line); | ||
| other.write('\n'); | ||
| } | ||
| other.flush(); | ||
| try { | ||
| new FileOutputStream(out ? FileDescriptor.out : FileDescriptor.err).write('x'); | ||
| other.println("write after close worked"); | ||
| } catch (IOException e) { | ||
| other.println("write after close: " + e.getMessage()); | ||
| } | ||
| return; | ||
| } | ||
| String java = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java"; | ||
| for (String which : new String[] {"out", "err"}) { | ||
| Process p = new ProcessBuilder(java, "-cp", System.getProperty("java.class.path"), "CloseStdout", which).start(); | ||
| InputStream closed = which.equals("out") ? p.getInputStream() : p.getErrorStream(); | ||
| InputStream other = which.equals("out") ? p.getErrorStream() : p.getInputStream(); | ||
| String first = new String(closed.readAllBytes()); | ||
| byte[] rest = other.readAllBytes(); | ||
| System.out.println(which + " closed: " + first); | ||
| System.out.println("other bytes: " + rest.length); | ||
| String text = new String(rest); | ||
| System.out.println(text.substring(text.lastIndexOf('\n', text.length() - 2) + 1).trim()); | ||
| System.out.println("exit: " + p.waitFor()); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.