JDK-4903591 : java.net.SocketException: socket write error (code=10004)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 1.3.1_08
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-08-08
  • Updated: 2003-09-29
  • Resolved: 2003-09-29
Description
We have a client and server application that does software distribution. The application is completely written in JAVA which is shipped by Sun Microsystems. We are currently using JDK "1.3.1_08" on Windows 2000/XP SP4. 

The server has a list of channels (Software packages) that the client is
trying download. During this process the server and the client get the
following exceptions upon which the download fails:

Server:
java.net.SocketException: socket write error (code=10004)
at java.net.SocketOutputStream.socketWrite(Native Method)
at java.net.SocketOutputStream.write(Unknown Source)
at
com.marimba.tools.csf.server.RatedOutputStream.write(RatedOutputStream.java:
112)
at
com.marimba.tools.csf.server.HTTPOutputStream.writeBuffer(HTTPOutputStream.j
ava:123)
at com.marimba.io.FastOutputStream.flushBuffer(FastOutputStream.java:128)
at com.marimba.io.FastOutputStream.write(FastOutputStream.java:242)
at com.marimba.io.FastOutputStream.write(FastOutputStream.java:210)
at
com.marimba.apps.transmitter.adp.GetFiles.writeFileStream(GetFiles.java:422)
at
com.marimba.apps.transmitter.adp.GetFiles.writeDiffReply(GetFiles.java:465)

CLIENT:
java.io.IOException: unexpected EOF,
n=-1,len=891,limit=465207491,total=687231
at
com.marimba.castanet.util.ChunkedInputStream.read(ChunkedInputStream.java:12
4)
at java.io.DataInputStream.readFully(Unknown Source)
at com.marimba.castanet.util.DiffInputStream.read(DiffInputStream.java:157)
at com.marimba.castanet.update.FileCache.download(FileCache.java:408)
at com.marimba.castanet.update.FileCache.download(FileCache.java:339)
at
com.marimba.castanet.update.Protocol_15$Request.download(Protocol_15.java:57
3)
at
com.marimba.castanet.update.Protocol_15$FileRequest.readReply(Protocol_15.ja
va:1079)
at
com.marimba.castanet.update.Protocol_15$FileRequest.handleReply(Protocol_15.
java:963)

The Client install fails because of an unexpected EOF which happened because
the server never completed writing all the data that the client was
expecting. On the other hand, the Server throws a socket write error (code
10004) which seems to be thrown from Sun's native code.

Comments
EVALUATION If a thread is blocked writing to a socket and if the socket is closed then the writer thread will throw a SocketException. This is normal. Prior to 1.4 the SocketException thrown on Windows was "java.net.SocketException: socket write error (code=10004)". In 1.4 winsock errors are translated into text so the SocketException more appropriate indicates the "socket is closed". You can duplicate the 10004 error with 1.3.1_xx using the following. import java.net.*; import java.io.*; public class Test { static class Writer implements Runnable { int port; Socket s; Writer(int port) { this.port = port; } public void run() { try { s = new Socket("127.0.0.1", port); OutputStream out = s.getOutputStream(); byte b[] = new byte[1024]; for (;;) { System.out.println("writing..."); out.write(b); } } catch (Exception x) { x.printStackTrace(); } } Socket socket() { return s; } } public static void main(String args[]) throws Exception { ServerSocket ss = new ServerSocket(0); Writer w = new Writer(ss.getLocalPort()); Thread thr = new Thread(w); thr.start(); Thread.currentThread().sleep(5000); w.socket().close(); } } In summary I would suggest that the customer examine their application to see if/where they are close the socket. In the interim I will mark this bug as incomplete. ###@###.### 2003-08-08 Confirmed as an application error. ###@###.### 2003-09-29
08-08-2003