#17655·netty

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

Author: pereamCreated Sep 29, 2026Updated Sep 29, 2026

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

java
// 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

java
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):

bash
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

  • netty/netty#9928 — "Problem with Connect timeout and Graal generated native-image"
  • netty/netty#13380 — "Misbehavior of AbstractScheduledEventExecutor.schedule in graalvm native image"
  • quarkusio/quarkus#8427 — netty 4.1.46+ fixed the same class of bug for ScheduledFutureTask