Bug Killer
Bug Killer

Reputation: 661

Is socket closed from my end or the other end

I'm reading from an InputStream, which wraps an HTTP connection, as follows:

       InputStream in = s3Object.getObjectContent();
       ByteArrayOutputStream out = new ByteArrayOutputStream(8192);
        byte[] tmp = new byte[8192];
        int r;
        while (true) {
            r = in.read(tmp);
            if(r <= 0) break;
            out.write(tmp,0,r);
        }
        in.close();

and getting a "Socket is closed" exception, for which the wire log shows the following:

DEBUG org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager - Shutting down
DEBUG org.apache.http.wire - << "Lr[0x86]{[0xf5]u[0xae][0xcc][0x8d]6[0x8a][0x16]([y%[0xb3][0xbb][0xd0]Va[0xc8]h[0x9][0x81][0xf2][0xb5][0x90]F[0x81])[0xf][0xfb]-`[0x94][0x14][0x4][0xb7];[0xd0][0x1d]"R>S[0xd1];[0xb1][0x81][0xad][0xc5][0xd6]:[0xc][0xf2]![0xdc][0xdb][0xce]g[0x5][0xdc]2"af[0xe6][0x15][0xb5]4[0xac][0xb9]L>[0x99]n7h[0x9e]z[0xdf][0x91]w[\r][0x19]!z[0x2])[0xde]d"
DEBUG org.apache.http.wire - << "J2[0x6][0xb0]b8j[0xc7]6[0xfa][0xb][0xe3]][0xf5][0x1b][0x94][0xa1][0xb6]F[0xda]k[0xb2]O[0xaa][0xfe][0xcd][0xe5]R[0x8f]w[0x84]JDx[0xe2][0xf4]3[0x15]d[0xf4]H*[0xce][0xc2][0xf3][0xec][0xd5][0x17]$[0xd6]Y[0xfd][0x8c]d[0xc9][0xa0][0x85][0xa2][0xc6][0xfb][0xee][0xdb][0xd9][0x1a][0x7][0xd7]R[0xc8]E'@[0x8b][0xe0][0xc3][0xe6][0xab][0xa3][0xbe]S^?[0x81][0xa3]8F[0xcf][0xe1]u[0xb2][0xbe][0xfc][0xa9][0xbb][0xba]^?[0x8c][0xba]/[0xd7][0xd5]+[0xf5][0xb2]+[0x16]M[0xc0][0xb0][0x3][0x8a]:5"
DEBUG org.apache.http.impl.conn.tsccm.ConnPoolByRoute - Closing connection [HttpRoute[{s}->https://svkbucket.s3.amazonaws.com]][null]
DEBUG org.apache.http.impl.conn.DefaultClientConnection - Connection shut down
DEBUG org.apache.http.impl.conn.DefaultClientConnection - Connection closed
DEBUG org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager - Released connection is not reusable.
DEBUG org.apache.http.impl.conn.tsccm.ConnPoolByRoute - Releasing connection [HttpRoute[{s}->https://svkbucket.s3.amazonaws.com]][null]
DEBUG org.apache.http.impl.conn.DefaultClientConnection - Connection closed
[Endpoint : 2] ERROR com.xxx.secures3proxy.activity.GetObjectActivity -   Exception:  Socket is closed
java.net.SocketException: Socket is closed
     at sun.security.ssl.SSLSocketImpl.checkEOF(SSLSocketImpl.java:1467)
     at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:149)
     at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:110)
     at org.apache.http.impl.io.AbstractSessionInputBuffer.read(AbstractSessionInputBuffer.java:191)
     at org.apache.http.impl.conn.LoggingSessionInputBuffer.read(LoggingSessionInputBuffer.java:82)
     at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:164)
    at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:138)
    at java.security.DigestInputStream.read(DigestInputStream.java:161)

Apache HttpClient 4.1.1.510.540 and Apache HttpCore 4.1.521.51

Does this mean that the remote end has closed the socket before I complete my read? Or that my HttpClient library or some library I'm using is closing the connection before all data can be read?

Upvotes: 1

Views: 3343

Answers (2)

Stephen C
Stephen C

Reputation: 719446

It looks like your application is shutting down the HttpClient connection pool too soon. It is not happening in the code you showed in your Question. That code looks like "an innocent victim".


Is this an issue with the HttpClient version I am using?

Probably not.

Or is something in my environment changing the behaviour?

Erm ... could be. Especially if "my environment" is an obscure way of saying some other part of your program.

Upvotes: 3

user207421
user207421

Reputation: 311039

"Socket is closed" exception

Your end closed the socket. If the peer had closed his end you would have got an EOS of some kind when reading, or an IOException: 'connection reset' when writing.

Upvotes: 0

Related Questions