2

There seems to be some confusion as well contradicting statements on various SO answers: What's causing my java.net.SocketException: Connection reset? . You can see here that the accepted answer states that the connection was closed by other side. But this is not true, closing a connection doesn't cause a connection reset. It is cauesed by "an underlying TCP/IP error."

What I want to know is if a SocketException: Connection reset means really besides "unerlying TCP/IP Error." What really causes this? As I doubt it has anything to do with the connection being closed (since closing a connection isn't an exception worthy flag, and reading from a closed connection is, but that isn't an "underlying TCP/IP error."

My hypothesis is this

Connection reset is caused from a server's failure to acknowledge an ACK packet (either wholly or just improperly as per TCP/IP). And that a SocketTimeoutException is generated only when no data is generated to be read (since this is thrown during a read after a certain duration, and read is waiting for data, but is not concerned with ACK packets). In other words, read() throws SocketTimeoutException if it didn't read any bytes of actual data (DATA LAYER) in its allotted time.

Community
  • 1
  • 1
Zombies
  • 25,039
  • 43
  • 140
  • 225
  • 'Connection reset is caused from a server's failure to acknowledge an ACK packet': no. It is caused by closing a connection that still has unread data; by sending data to a connection that the peer has already closed; or by messing around with `SO_LINGER` before closing. – user207421 Mar 23 '21 at 03:50

2 Answers2

1

In my experience, it happens when the client aborts a request (user closed the tab or clicked another link).

Guillaume
  • 14,306
  • 3
  • 43
  • 40
  • 2
    You're a bit talking in webapplication context. The question seems not to be about webapplications. – BalusC Apr 22 '10 at 19:53
  • I'm not sure what the question really is, but the linked question showed a Tomcat error log. The 'connection reset' message definitively occurs when the clients abruptly closes the connection, maybe in other situations too though. – Guillaume Apr 22 '10 at 20:38
1

From the openjdk6 sources, it appears that the "Connection reset" is issued when an attempt to read data fails with an ECONNRESET error (Linux & Solaris) or WSAECONNRESET (Windows).

In my experience the typical cause is the party on the other end of the socket closed the socket without first performing a shutdown.

Devon_C_Miller
  • 16,248
  • 3
  • 45
  • 71
  • In `jdk/src/solaris/native/java/net/SocketInputStream.c` the "Connection reset" message can be caused by `EPIPE` as well as `ECONNRESET`. – hertzsprung Mar 05 '13 at 11:58
  • Shutdown is not necessary and does not cause this error if omitted. It mostly happens when the peer closes the connection without reading all the pending data. – user207421 Mar 23 '21 at 03:49