Flush ObjectOutputStreams after construction

This protects against deadlocks between the writing and reading end,
since the ObjectOutputStream constructor writes a header, but does not
flush, and the ObjectInputStream constructor reads the header, and
blocks until it's read.
This commit is contained in:
James Roper
2013-11-01 13:26:07 -04:00
committed by Mark Harrah
parent 259bb192cf
commit b337f3d9ac
2 changed files with 4 additions and 0 deletions
@@ -92,6 +92,8 @@ public class ForkMain {
Socket socket = new Socket(InetAddress.getByName(null), Integer.valueOf(args[0]));
final ObjectInputStream is = new ObjectInputStream(socket.getInputStream());
final ObjectOutputStream os = new ObjectOutputStream(socket.getOutputStream());
// Must flush the header that the constructor writes, otherwise the ObjectInputStream on the other end may block indefinitely
os.flush();
try {
try {
new Run().run(is, os);