nats.java icon indicating copy to clipboard operation
nats.java copied to clipboard

NUID generate same consumers names for native compiled executable

Open Andro999b opened this issue 11 months ago • 2 comments

Proposed change

Reflect in DOCS that io.nats.client.NUID should be initialized at runtime as well:

--initialize-at-run-time=io.nats.client.NUID

Use case

Native compiled executables.

Contribution

No response

Andro999b avatar Dec 06 '24 08:12 Andro999b

@Andro999b Are you sure, because it depends on RandomUtils, which is already identified in the readme. Maybe it's a Quarkus specific thing?

  • Is it the are static things in the NUID class that are problematic?
  • Would just saying initialize at runtime for the NUID cover RandomUtils since it's a dependency?
  • Have you verified the consumer names are identical? It could be that they are very similar and may only differ in the last character.

scottf avatar Dec 06 '24 15:12 scottf

@scottf I'm pretty sure about this. I have updated my previous reproducer so you can check it: https://github.com/Andro999b/nats-java-native-build-reproducer

Don't know if this Quarkus specific or not. But NUID have static global instance that will be initialized at build time by default (This can be checked in GraalVM class initilization report target/native-build-1.0.0-SNAPSHOT-native-image-source-jar/reports). Call to the RandomUtils(initialized at runtime) does not matter here because GraalVM does inline methods during compilation.

Andro999b avatar Dec 09 '24 08:12 Andro999b

@Andro999b @YunaBraska Would it be sufficient to just note about NUID, since it depends on RandomUtils which depends on SecureRandom, or do you have to identify all 3? So this:

* `--initialize-at-run-time=io.nats.client.NUID`.

or this:

* `--initialize-at-run-time=java.security.SecureRandom`.
* `--initialize-at-run-time=io.nats.client.support.RandomUtils`
* `--initialize-at-run-time=io.nats.client.NUID`.

And if it's all 3, is there an order that matters?

scottf avatar Jul 02 '25 20:07 scottf

@scottf We are using this setting currently to allow native build:

--initialize-at-run-time=io.nats.client.support.RandomUtil
--initialize-at-run-time=io.nats.client.NUID
--initialize-at-run-time=java.security.SecureRandom

as i recall you need to specify all of them (order does not matter)

Andro999b avatar Jul 03 '25 09:07 Andro999b

Fixed in this PR https://github.com/nats-io/nats.java/pull/1350

scottf avatar Jul 04 '25 15:07 scottf