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 17:20:01 +11:00 committed by Mark Harrah
parent 259bb192cf
commit b337f3d9ac
2 changed files with 4 additions and 0 deletions

View File

@ -49,6 +49,8 @@ private[sbt] object ForkTests
case _: java.net.SocketException => return
}
val 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()
val is = new ObjectInputStream(socket.getInputStream)
try {

View File

@ -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);