Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8238579

HttpsURLConnection drops the timeout and hangs forever in read

XMLWordPrintable

    • b14
    • x86_64
    • linux_ubuntu
    • Not verified

        ADDITIONAL SYSTEM INFORMATION :
        Confirmed in openjdk version "11.0.5" 2019-10-15 and openjdk version "1.8.0_232"

        A DESCRIPTION OF THE PROBLEM :
        HttpUrlConnection.writeRequests contains logic that retries on write errors. In that code path setNewClient or setProxiedClient are called. AbstractDelegateHttpsURLConnection (subclassed by DelegateHttpsURLConnection) overrides both setNewClient and setProxiedClient. Contrary to the implementation in HttpUrlConnection, these implementations do not call NetworkClient.setReadTimeout. Consequently, the new client does not have the timeout set.
        This is a similar pattern to https://bugs.openjdk.java.net/browse/JDK-4646885

        This leads to infinitely hung applications in scenarios, where the retry code path in HttpUrlConnection.writeRequests executes and the server silently drops the TCP connection.

        The bug can be reproduced every time with appropriate failure injection.

        Below are the stack traces from hung applications.

        JDK 11

        at java.net.SocketInputStream.socketRead0(java.base@11.0.5/Native Method)
        at java.net.SocketInputStream.socketRead(java.base@11.0.5/SocketInputStream.java:115)
        at java.net.SocketInputStream.read(java.base@11.0.5/SocketInputStream.java:168)
        at java.net.SocketInputStream.read(java.base@11.0.5/SocketInputStream.java:140)
        at sun.security.ssl.SSLSocketInputRecord.read(java.base@11.0.5/SSLSocketInputRecord.java:448)
        at sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(java.base@11.0.5/SSLSocketInputRecord.java:68)
        at sun.security.ssl.SSLSocketImpl.readApplicationRecord(java.base@11.0.5/SSLSocketImpl.java:1104)
        at sun.security.ssl.SSLSocketImpl$AppInputStream.read(java.base@11.0.5/SSLSocketImpl.java:823)
        - locked <0x0000000630a20790> (a sun.security.ssl.SSLSocketImpl$AppInputStream)
        at java.io.BufferedInputStream.fill(java.base@11.0.5/BufferedInputStream.java:252)
        at java.io.BufferedInputStream.read1(java.base@11.0.5/BufferedInputStream.java:292)
        at java.io.BufferedInputStream.read(java.base@11.0.5/BufferedInputStream.java:351)
        - locked <0x0000000630ae0ac0> (a java.io.BufferedInputStream)
        at sun.net.www.http.HttpClient.parseHTTPHeader(java.base@11.0.5/HttpClient.java:746)
        at sun.net.www.http.HttpClient.parseHTTP(java.base@11.0.5/HttpClient.java:689)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(java.base@11.0.5/HttpURLConnection.java:1610)
        - locked <0x0000000630a08718> (a sun.net.www.protocol.https.DelegateHttpsURLConnection)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(java.base@11.0.5/HttpURLConnection.java:1515)
        - locked <0x0000000630a08718> (a sun.net.www.protocol.https.DelegateHttpsURLConnection)
        at java.net.HttpURLConnection.getResponseCode(java.base@11.0.5/HttpURLConnection.java:527)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(java.base@11.0.5/HttpsURLConnectionImpl.java:334)

        Thread 18 (Thread 0x7fd07fcfb700 (LWP 5340)):
        #0 0x00007fd0f74b4a66 in __libc_recv (fd=10, buf=0x7fd07fce9830, len=5, flags=0) at ../sysdeps/unix/sysv/linux/recv.c:28
        #1 0x00007fd0b840f10d in ?? () from /usr/lib/jvm/java-11-openjdk-amd64/lib/libnet.so
        #2 0x00007fd0b840ea4e in Java_java_net_SocketInputStream_socketRead0 () from /usr/lib/jvm/java-11-openjdk-amd64/lib/libnet.so
        #3 0x00007fd0d853f990 in ?? ()
        #4 0x0000000600000000 in ?? ()
        #5 0x0000000630ae6230 in ?? ()
        #6 0x0000000630eac9f0 in ?? ()
        #7 0x00007fd07fcf9888 in ?? ()
        #8 0x00007fd0b9b685cd in ?? ()
        #9 0x00007fd07fcf98f8 in ?? ()
        #10 0x00007fd07fcf98a0 in ?? ()
        #11 0x0000000000000000 in ?? ()


        JDK 8:

        java.net.SocketInputStream.socketRead0(Native Method)
        java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
        java.net.SocketInputStream.read(SocketInputStream.java:171)
        java.net.SocketInputStream.read(SocketInputStream.java:141)
        sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
        sun.security.ssl.InputRecord.read(InputRecord.java:503)
        sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983) => holding Monitor(java.lang.Object@438851338})
        sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:940)
        sun.security.ssl.AppInputStream.read(AppInputStream.java:105) => holding Monitor(sun.security.ssl.AppInputStream@2010412364})
        java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
        java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
        java.io.BufferedInputStream.read(BufferedInputStream.java:345) => holding Monitor(java.io.BufferedInputStream@1680899557})
        sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:735)
        sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678)
        sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1587) => holding Monitor(www.protocol.https.DelegateHttpsURLConnection@1729312334'>sun.net.www.protocol.https.DelegateHttpsURLConnection@1729312334})
        sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492) => holding Monitor(www.protocol.https.DelegateHttpsURLConnection@1729312334'>sun.net.www.protocol.https.DelegateHttpsURLConnection@1729312334})
        java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
        sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:347)

        Thread 23 (Thread 0x7f99f814c700 (LWP 14213)):
        #0 0x00007f9a1a3ffa66 in __libc_recv (fd=25, buf=0x7f99f813a8b0, len=5, flags=0) at ../sysdeps/unix/sysv/linux/recv.c:28
        #1 0x00007f99f868916d in NET_Read () from /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/libnet.so
        #2 0x00007f99f8688af2 in Java_java_net_SocketInputStream_socketRead0 () from /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/libnet.so
        #3 0x00007f9a0418f427 in ?? ()
        #4 0x00007f9a00000000 in ?? ()
        #5 0x00007f99f814a948 in ?? ()
        #6 0x00007f99f8264d38 in ?? ()
        #7 0xa08c80390f95f200 in ?? ()
        #8 0x00007f9a00b8e158 in ?? ()
        #9 0x00007f9a00a7bb88 in ?? ()
        #10 0x00007f99f814a930 in ?? ()
        #11 0x0000000000000000 in ?? ()



          1. hooks_2.c
            1 kB
          2. hooks.c
            1 kB
          3. JDK_hang_repro.tar.gz
            5 kB

              dfuchs Daniel Fuchs
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              9 Start watching this issue

                Created:
                Updated:
                Resolved: