7

I've been working on this bug for several days now and couldn't solve it.

I wrote an HttpsURLConnection client to upload large files(>1GB) using POST requests. I also implemented the server side using com.sun.net.httpserver.HttpServer. As the files are quite big I have to use the: setFixedLengthStreamingMode/setChunkedStreamingMode settings on my connection (bug is reproduced using either). Please notice I'm using an HTTPS connection for the upload as well.

I'm uploading the file to several servers simultaneously (seperate thread for each http client, connected to a different server). I have set a limit on the concurrent uploads so each time only X threads have an open UrlConnection (bug was reproduced with X=[1..4]). (The other threads wait on a semaphore)

My problem is such: When uploads takes less than 5 minutes (less than 4:50 minutes to be accurate) everything works just fine. If the first batch of threads takes more then 5 minutes to finish then an Exception is thrown for every active thread:

java.io.IOException: Error writing request body to server at sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.checkError(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.write(Unknown Source)

The exception is thrown while trying to write to the HttpURLConnection output stream. [outputStream.write(buffer,0,len);]

The next batch of threads will work just fine (even if they take more then 5 minutes). Please notice that the servers are completely identical, and now the process will not fail thus leading me to think that the problem is not on the server side. (If it was then the second batch was suppose to fail after 5 minutes as well...)

I have reproduced this issue with/without connect/read timeouts on the connection. Furthermore, on the server side I've seen the file is being created and growing until the exception occurs. About 20-40 seconds after the client throws an exception the server will throw an IOException "read timeout".

I have collected a TCP/IP sample using wireshark and saw that the server sends me a FIN packet at about the time of the client exception, I have no idea why. (All connection seems functioning prior to that)

I have read many threads on similiar issues but couldn't find any proper solution. (including Using java.net.URLConnection to fire and handle HTTP requests)

Any ideas on why is this happening? How can I find the cause of it? How can I solve it?

Many Thanks.

P.S I didn't publish the code because it is pretty long... But if it could help understanding my problem I will be glad to do so.

Community
  • 1
  • 1
Oren Hacohen
  • 161
  • 8

0 Answers0