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

(ch) sun.nio.ch.SocketAdaptor does not respect timeout in case of system date/time change and blocks

XMLWordPrintable

    • generic
    • generic

        FULL PRODUCT VERSION :


        A DESCRIPTION OF THE PROBLEM :
        When using SocketChannel.read() after a timeout has been set on the socket, it will fail if the system date/time is changed during the call to read().

        This is visible here:

        http://hg.openjdk.java.net/jdk8/jdk8/jdk/annotate/687fd7c7986d/src/share/classes/sun/nio/ch/SocketAdaptor.java#l203

        The function uses System.currentTimeMillis() whith is not monothonic. So changing the system date during a call to read() may make this function loop over and over and thus nos respecting the timeout.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        - Create a SocketChannel
        - Set a timeout on the socket, like 1000ms
        - Call read() in a loop and display some text between calls
        - Change date (like 1 year in the past)


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The timeout stay 1000ms and the code continue executing normally
        ACTUAL -
        The next read() will never return (I mean, the timeout is buggy and depends on the date you pick)

        REPRODUCIBILITY :
        This bug can be reproduced always.

              bpb Brian Burkhalter
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: