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

Roger Riggs rriggs at openjdk.org
Wed Jun 14 13:51:02 UTC 2023


On Wed, 14 Jun 2023 13:46: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 two additional commits since the last revision:
> 
>  - more cleanup
>  - whitespaces

Changes requested by rriggs (Reviewer).

src/java.net.http/share/classes/jdk/internal/net/http/common/TimeSource.java line 36:

> 34:  * caused by changes to the wall clock. Consequently, callers should use
> 35:  * instants returned by this time source solely for the purpose of
> 36:  * comparing them with other instants returned by this same time source.

Do not use `Instant` as the value from this time source. It is not comparable with the real Instants and would be misleading lead to bugs.

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

PR Review: https://git.openjdk.org/jdk/pull/14450#pullrequestreview-1479500686
PR Review Comment: https://git.openjdk.org/jdk/pull/14450#discussion_r1229651020


More information about the net-dev mailing list