RFR: 8309939: HttpClient should not use Instant.now() as Instant source for deadlines [v5]

Daniel Jeliński djelinski at openjdk.org
Fri Jun 16 12:49:05 UTC 2023


On Wed, 14 Jun 2023 15:39:10 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:

>> The HttpClient uses `Instant.now()` to create deadlines for timeouts. This could have undesirable effects since `Instant.now()` is linked to the wall clock, which is not monotonic. This fix changes the HttpClient to use a monotonic instant source based on `System.nanoTime()` for the purpose of setting and comparing deadlines.
>
> Daniel Fuchs has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Use Deadline rather than Instant

src/java.net.http/share/classes/jdk/internal/net/http/common/Deadline.java line 203:

> 201:     @Override
> 202:     public String toString() {
> 203:         return deadline.toString();

I'm not sure about using `Instant.toString` here; if we ever log a `Deadline` instance along with the current time and the clock skews, we will need to read the code along with the logs to figure out which date represents a deadline and which one represents an instant.
I guess the problem would also go away if we initialized the first NanoSource with something other than Instant.now().

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/14450#discussion_r1232206107


More information about the net-dev mailing list