javax.net.ssl.SSLException:在接收对等方的 close_notify 和 java 11 之前关闭入站
javax.net.ssl.SSLException: closing inbound before receiving peer's close_notify with java 11
我在 java 11 的 http 响应上调用 close 时遇到以下异常。这曾经与 java 8.
一起使用
Caused by: javax.net.ssl.SSLException: closing inbound before receiving peer's close_notify
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:133)
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:313)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:269)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:260)
at java.base/sun.security.ssl.SSLSocketImpl.shutdownInput(SSLSocketImpl.java:737)
at java.base/sun.security.ssl.SSLSocketImpl.shutdownInput(SSLSocketImpl.java:716)
at org.apache.http.impl.BHttpConnectionBase.close(BHttpConnectionBase.java:327)
at org.apache.http.impl.conn.LoggingManagedHttpClientConnection.close(LoggingManagedHttpClientConnection.java:81)
at org.apache.http.impl.conn.CPoolEntry.closeConnection(CPoolEntry.java:70)
at org.apache.http.impl.conn.CPoolProxy.close(CPoolProxy.java:86)
at org.apache.http.impl.execchain.ConnectionHolder.releaseConnection(ConnectionHolder.java:103)
at org.apache.http.impl.execchain.ConnectionHolder.close(ConnectionHolder.java:156)
at org.apache.http.impl.execchain.HttpResponseProxy.close(HttpResponseProxy.java:62)
上述异常发生在以下代码中调用 response.close() 时:
HttpGet httpRequest = new HttpGet(url);
CloseableHttpResponse response = null;
BufferedReader reader = null;
try {
response = httpClient.execute(httpRequest);
reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while((line = reader.readLine()) != null) {
// do something with the line
}
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
if (response != null) {
response.close();
}
if (reader != null) {
reader.close();
}
}
我正在使用 httpclient 4.5.3。
我在 reader.close() 上也观察到同样的错误。
感谢任何帮助。
您试图以错误的顺序关闭请求和 reader。在我看来,您最好重新格式化代码以使用自动关闭资源的 try-with-resource 块,这样您就再也不会 运行 遇到这个问题:
HttpGet httpRequest = new HttpGet(url);
try (CloseableHttpResponse response = httpClient.execute(httpRequest)) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()))) {
String line = "";
while ((line = reader.readLine()) != null) {
// do something with the line
}
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
我在 java 11 的 http 响应上调用 close 时遇到以下异常。这曾经与 java 8.
一起使用Caused by: javax.net.ssl.SSLException: closing inbound before receiving peer's close_notify
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:133)
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:313)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:269)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:260)
at java.base/sun.security.ssl.SSLSocketImpl.shutdownInput(SSLSocketImpl.java:737)
at java.base/sun.security.ssl.SSLSocketImpl.shutdownInput(SSLSocketImpl.java:716)
at org.apache.http.impl.BHttpConnectionBase.close(BHttpConnectionBase.java:327)
at org.apache.http.impl.conn.LoggingManagedHttpClientConnection.close(LoggingManagedHttpClientConnection.java:81)
at org.apache.http.impl.conn.CPoolEntry.closeConnection(CPoolEntry.java:70)
at org.apache.http.impl.conn.CPoolProxy.close(CPoolProxy.java:86)
at org.apache.http.impl.execchain.ConnectionHolder.releaseConnection(ConnectionHolder.java:103)
at org.apache.http.impl.execchain.ConnectionHolder.close(ConnectionHolder.java:156)
at org.apache.http.impl.execchain.HttpResponseProxy.close(HttpResponseProxy.java:62)
上述异常发生在以下代码中调用 response.close() 时:
HttpGet httpRequest = new HttpGet(url);
CloseableHttpResponse response = null;
BufferedReader reader = null;
try {
response = httpClient.execute(httpRequest);
reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while((line = reader.readLine()) != null) {
// do something with the line
}
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
if (response != null) {
response.close();
}
if (reader != null) {
reader.close();
}
}
我正在使用 httpclient 4.5.3。 我在 reader.close() 上也观察到同样的错误。
感谢任何帮助。
您试图以错误的顺序关闭请求和 reader。在我看来,您最好重新格式化代码以使用自动关闭资源的 try-with-resource 块,这样您就再也不会 运行 遇到这个问题:
HttpGet httpRequest = new HttpGet(url);
try (CloseableHttpResponse response = httpClient.execute(httpRequest)) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()))) {
String line = "";
while ((line = reader.readLine()) != null) {
// do something with the line
}
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}