Stuck in java.net.SocketInputStream.socketRead0 (native method)

I am stuck in java.net.SocketInputStream.socketRead0 (Native Method). See Dump flow, as shown below, it has been in this state for 3 hours.

Thread-0" prio=10 tid=0x00007facd02a5000 nid=0x309 runnable [0x00007facd4a43000] java.lang.Thread.State: RUNNABLE at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(SocketInputStream.java:150) at java.net.SocketInputStream.read(SocketInputStream.java:121) at sun.security.ssl.InputRecord.readFully(InputRecord.java:442) at sun.security.ssl.InputRecord.read(InputRecord.java:480) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927) - locked <0x00000000e34a0428> (a java.lang.Object) at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:884) at sun.security.ssl.AppInputStream.read(AppInputStream.java:102) - locked <0x00000000e34a0590> (a sun.security.ssl.AppInputStream) at java.io.BufferedInputStream.fill(BufferedInputStream.java:235) at java.io.BufferedInputStream.read1(BufferedInputStream.java:275) at java.io.BufferedInputStream.read(BufferedInputStream.java:334) - locked <0x00000000e30408b8> (a java.io.BufferedInputStream) at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:633) at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:579) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1322) - locked <0x00000000e3031d00> (a sun.net.www.protocol.https.DelegateHttpsURLConnection) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254) - locked <0x00000000e3031c80> (a sun.net.www.protocol.https.HttpsURLConnectionImpl) 

And I set the connection timeout and read timeout for URLConnection. The following is a snippet of code. Therefore, I do not know why it hangs on java.net.SocketInputStream.socketRead0. Sometimes I have such a problem. Any suggestion appreciated!

 public String sendPost(String params) throws Throwable { PrintWriter out = null; String htmlContent = null; try { StringBuffer strBuffer = new StringBuffer(); URL url = new URL(this.webUrl); URLConnection urlConnection = url.openConnection(); urlConnection.setConnectTimeout(3000); urlConnection.setReadTimeout(3000); urlConnection.setRequestProperty("accept", "*/*"); urlConnection.setRequestProperty("connection", "Keep-Alive"); urlConnection.setRequestProperty("user-agent", "***"); urlConnection.setDoOutput(true); urlConnection.setDoInput(true); out = new PrintWriter(urlConnection.getOutputStream()); out.print(params); out.flush(); BufferedReader bufferdReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream(), "utf-8")); String readLine = null; try { while ((readLine = bufferdReader.readLine()) != null) { strBuffer.append(readLine); } } catch (Throwable e) { return htmlContent; } htmlContent = strBuffer.toString(); bufferdReader.close(); 
+5
source share
2 answers

I think this is a bug with URLConnection. Use sockets and timeout to verify.

0
source

Today I discovered this error on our systems. This is a bug in the JDK caused by the embedded implementation used in java. It was only fixed on September 21, 2016, so it should be available in later versions of the JDK.

This is an error: https://bugs.openjdk.java.net/browse/JDK-8075484

If you can't wait, it looks like someone has created a workaround: https://github.com/nukesparrow/JNativeSocket

0
source

Source: https://habr.com/ru/post/1203116/


All Articles