Quarkus: ThreadLocalRandom generates always the same numbers

Created on 24 Aug 2020  路  6Comments  路  Source: quarkusio/quarkus

Describe the bug
(Describe the problem clearly and concisely.)
ThreadLocalRandom.current().nextLong() always generates the same numbers on each startup. This only happens when I run a native image.
Expected behavior
(Describe the expected behavior clearly and concisely.)
ThreadLocalRandom.current().nextLong() generates different numbers on each startup.
Actual behavior
(Describe the actual behavior clearly and concisely.)
ThreadLocalRandom.current().nextLong() generates same numbers on each startup.

To Reproduce
Steps to reproduce the behavior:

  1. Generate random numbers with ThreadLocalRandom.current().nextLong() Example:
package org.acme;
import io.quarkus.runtime.StartupEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.enterprise.event.Observes;
import javax.ws.rs.core.Application;
import java.util.concurrent.ThreadLocalRandom;
public class ExampleApp extends Application {
    private static final Logger _logger = LoggerFactory.getLogger(ExampleApp.class);
    public void onInit(@Observes StartupEvent evt) {
        for (int i = 0; i < 10; i++) {
            _logger.info("Random: {}", ThreadLocalRandom.current().nextLong());
        }
    }
}
  1. Build a native image
  2. Run it

Configuration

quarkus.package.type=native
quarkus.native.container-build=true
quarkus.native.container-runtime=docker

Screenshots
(If applicable, add screenshots to help explain your problem.)
image

Environment (please complete the following information):

  • Output of uname -a or ver: Linux nb-xxx 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
  • Output of java -version: openjdk version "11.0.8" 2020-07-14
  • GraalVM version (if different from Java): 20.1.0
  • Quarkus version or git rev: 1.7.0.Final
  • Build tool (ie. output of mvnw --version or gradlew --version): Gradle 6.4.1

Additional context
(Add any other context about the problem here.)

kinbug

All 6 comments

Seems to be related to https://github.com/oracle/graal/issues/1610 and the fix should be available in GraalVM 20.2.0

/cc @galderz wondering if we would want that one backported to Mandrel?

Bad news: I just tested in 20.2.0 and that doesn't seem to be fixed for ThreadLocalRandoms or Math.random :disappointed:

Bad news: I just tested in 20.2.0 and that doesn't seem to be fixed for ThreadLocalRandoms or Math.random 馃槥

It looked surprising that a year old fix didn't make it to 20.2 which was recently released. So I had a look and it appears that this feature isn't enabled by default in Graal VM. I am not sure if that was intentional. I have opened https://github.com/oracle/graal/pull/2790 with a proposed fix.

https://github.com/oracle/graal/issues/1610 is included in both Mandrel 20.1 and 20.2. Hope the improvement fix gets included too.

Just dropping another issue for you to be aware of: https://github.com/oracle/graal/pull/2993

Was this page helpful?
0 / 5 - 0 ratings