GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — netty-common 4.2: SystemTicker.START_TIME missing from --initialize-at-run-time (native-image regression of #9928) · Issue #17655 · netty/netty

netty-common 4.2: SystemTicker.START_TIME missing from --initialize-at-run-time (native-image regression of #9928) #17655

New issue
Copy link
New issue
Copy link
Closed
#17677
Closed
netty-common 4.2: SystemTicker.START_TIME missing from --initialize-at-run-time (native-image regression of #9928)#17655
#17677
Copy link

Description

@peream
peream
opened on Sep 29, 2026
Issue body actions

Summary

In netty-common 4.2.x, the memoized System.nanoTime() epoch moved from
ScheduledFutureTask to the new io.netty.util.concurrent.SystemTicker, but
SystemTicker was not added to the --initialize-at-run-time list in
META-INF/native-image/io.netty/netty-common/native-image.properties.
As a result, in GraalVM native images the epoch is captured at image build time,
which is exactly the bug that was fixed for ScheduledFutureTask in #9928
(see also #13380, quarkusio/quarkus#8427).

Because System.nanoTime() is relative to the machine's boot, a native image
built on one boot session (or one machine) and then run after a reboot
(or on another host) sees Ticker.systemTicker().nanoTime() return a large
negative value, and scheduled tasks misbehave — in our case a 10-second
connect timeout fired immediately.

Affected

  • netty-common 4.2.17.Final (any 4.2.x that contains Ticker/SystemTicker)
  • GraalVM native-image (tested with GraalVM for JDK 25)
  • Anything that schedules through AbstractScheduledEventExecutor (event-loop scheduling);
    we hit it through netty-codec-native-quic (the client's connect timeout).
    (HashedWheelTimer is not affected — it keeps startTime in an instance field.)

Root cause

// io.netty.util.concurrent.SystemTicker
class SystemTicker implements Ticker {
    static final SystemTicker INSTANCE = new SystemTicker();
    private static final long START_TIME = System.nanoTime();   // <-- build-time constant in native image

    @Override public long initialNanoTime() { return START_TIME; }
    @Override public long nanoTime()        { return System.nanoTime() - START_TIME; }
    ...
}

META-INF/native-image/io.netty/netty-common/native-image.properties contains:

Args = --initialize-at-run-time=io.netty.util.AbstractReferenceCounted,
       io.netty.util.concurrent.GlobalEventExecutor,
       io.netty.util.concurrent.ImmediateEventExecutor,
       io.netty.util.concurrent.ScheduledFutureTask,          <-- fix for #9928
       io.netty.util.internal.ThreadLocalRandom, ...

io.netty.util.concurrent.SystemTicker is not in that list, so it is
initialized during image building and START_TIME becomes the build machine's
System.nanoTime().

Minimal reproduction

import io.netty.util.concurrent.Ticker;

public class Repro {
    public static void main(String[] args) {
        Ticker t = Ticker.systemTicker();
        System.out.println("machine nanoTime       = " + System.nanoTime());
        System.out.println("ticker.initialNanoTime = " + t.initialNanoTime());
        System.out.println("ticker.nanoTime()      = " + t.nanoTime());
    }
}

Build — --initialize-at-build-time is added here to force the build-time initialization
that this class receives in real application images (our app image exhibits exactly the
behaviour below, and adding --initialize-at-run-time=...SystemTicker fixes it):

native-image -cp .:netty-common-4.2.17.Final.jar \
  --initialize-at-build-time=io.netty.util.concurrent.Ticker,io.netty.util.concurrent.SystemTicker \
  -o repro Repro

Observed:

# run right after building (same boot session)
machine nanoTime       = 7769247768314
ticker.initialNanoTime = 7742979431308   <-- frozen at BUILD time (uptime of build machine ≈ 7743 s)
ticker.nanoTime()      =   26268372564   <-- "time since the image was built", not ≈ 0

# same binary, simulated fresh boot (monotonic clock offset via a time namespace)
machine nanoTime       = 400261931765    <-- uptime 400 s
ticker.initialNanoTime = 7742979431308
ticker.nanoTime()      = -7342717471485  <-- huge negative value

On the JVM the same program prints ticker.nanoTime() ≈ 0 — only the native image is affected.

Real-world impact (netty-quic client in a native image)

Our QUIC client (netty-codec-native-quic) failed every time with:

订阅流异常结束,将重连:https://<host>:9070/api/h3sub
  -> connection timed out: QuicConnectionAddress{EPHEMERAL} -> QuicConnectionAddress{EPHEMERAL}
  • Works fine on the JVM (same jar, same config, same host).
  • In the native image it worked when run in the boot session in which the image was built,
    and failed deterministically after a machine reboot.
  • Packet capture shows the client's QuicheQuicChannel connect-timeout task (scheduled for
    10 s) executing as soon as the event loop processed the server's first packet, killing the handshake.
  • Measured threshold: the binary fails whenever the current uptime < the uptime at image build time
    (we bisected it: simulated uptime 5000 s → OK, 4980 s → fail; the build JVM had started at uptime 4997 s).
  • Adding --initialize-at-run-time=io.netty.util.concurrent.SystemTicker fixes it completely
    (verified on the same simulated-reboot setup).

Suggested fix

Add the class to the existing run-time-initialization list in
META-INF/native-image/io.netty/netty-common/native-image.properties:

--initialize-at-run-time=...,io.netty.util.concurrent.Ticker,io.netty.util.concurrent.SystemTicker,...

(or, more robustly, stop memoizing the epoch in a static field — e.g. make START_TIME
an instance field of the INSTANCE singleton, or compute initialNanoTime() lazily —
so that initialNanoTime() and nanoTime() always share the same runtime time base).

The same entry is probably also needed in the GraalVM reachability metadata repository,
since netty's file notes it is overridden by graalvm-reachability-metadata.

Environment

  • netty-common 4.2.17.Final, netty-codec-native-quic 4.2.17.Final
  • GraalVM for JDK 25 (native-image, build flags --static-nolibc -H:+UnlockExperimentalVMOptions -H:+AddAllCharsets --enable-native-access=ALL-UNNAMED -march=compatibility)
  • Linux 6.12 (RHEL 10), x86_64

References

  • Problem with Connect timeout and Graal generated native-image #9928 — "Problem with Connect timeout and Graal generated native-image"
  • Misbehavior of AbstractScheduledEventExecutor.schedule in graalvm native image #13380 — "Misbehavior of AbstractScheduledEventExecutor.schedule in graalvm native image"
  • Update Netty library to 4.1.46.Final or higher to improve GraalVM support quarkusio/quarkus#8427 — netty 4.1.46+ fixed the same class of bug for ScheduledFutureTask

Activity

  1. normanmaurer
    closed this as completedin #17677on Oct 2, 2026
  2. violetagg
    added a commit that references this issue on Oct 2, 2026

    common: initialize SystemTicker at runtime in native images (netty#17677

    This issue will close once commit 658b570 is merged into the '4.2' branch.
    658b570
  3. normanmaurer
    added a commit that references this issue on Oct 24, 2026

    Auto-port 5.0: common: initialize SystemTicker at runtime in native i…

    This issue will close once commit 4385934 is merged into the '4.2' branch.
    4385934
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.