Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ThreadLocalRandom generates always the same numbers #11573

Closed
knupfera opened this issue Aug 24, 2020 · 6 comments · Fixed by #11588
Closed

ThreadLocalRandom generates always the same numbers #11573

knupfera opened this issue Aug 24, 2020 · 6 comments · Fixed by #11588
Labels
kind/bug Something isn't working
Milestone

Comments

@knupfera
Copy link

knupfera commented Aug 24, 2020

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 Add proper logging #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.)

@knupfera knupfera added the kind/bug Something isn't working label Aug 24, 2020
@gastaldi
Copy link
Contributor

Seems to be related to oracle/graal#1610 and the fix should be available in GraalVM 20.2.0

@gsmet
Copy link
Member

gsmet commented Aug 24, 2020

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

@gastaldi
Copy link
Contributor

gastaldi commented Aug 24, 2020

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

@jaikiran
Copy link
Member

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 oracle/graal#2790 with a proposed fix.

@gsmet gsmet added this to the 1.7.1.Final milestone Aug 25, 2020
gsmet pushed a commit to gsmet/quarkus that referenced this issue Aug 25, 2020
@galderz
Copy link
Member

galderz commented Aug 27, 2020

oracle/graal#1610 is included in both Mandrel 20.1 and 20.2. Hope the improvement fix gets included too.

@pivovarit
Copy link
Contributor

Just dropping another issue for you to be aware of: oracle/graal#2993

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants