jsr354-api icon indicating copy to clipboard operation
jsr354-api copied to clipboard

MonetaryException: No MonetaryAmountsSingletonSpi loaded in Kubernetes

Open iakunin opened this issue 4 years ago • 19 comments

I want to draw some community attention to my question on StackOverflow. Don't want it to be copy-pasted here that's why I only left a link to StackOverflow.

Thanks in advance for any feedback.

iakunin avatar Apr 28 '20 07:04 iakunin

I hope @atsticks might have a chance to look at it, he's the Kubernetes guy, I am not working with Kubernetes right now, so I can't help with that I'm afraid.

keilw avatar Apr 28 '20 09:04 keilw

@keilw thank you so much for answering. I don't rule out that the problem may be outside of Kubernetes. Unfortunately, this problem is pretty vague.

I will give you any information you needed to solve that problem.

iakunin avatar Apr 28 '20 09:04 iakunin

@atsticks sorry for my impatience, but could you have a look at my problem? Any advice will be very valuable for me.

iakunin avatar May 07 '20 19:05 iakunin

There was at least one ticket in Moneta specific to Java 11 (although it may not even be a Moneta problem) and Spring Boot, so did you get a chance to try it with Java 8 to 10 as well? Then it'll show, if it is related to Kubernetes or maybe started with Java 11, which as we know includes many changes that break things, therefore please try an older JDK, too.

keilw avatar May 07 '20 21:05 keilw

@keilw I finally came up with a solution: https://stackoverflow.com/a/61715268/3456163

I've discovered that:

  1. The problem is not related to Kubernetes at all.
  2. The problem is not reproduced on Java 8. Thanks for your suggestion to check this.

For more details see this repo: https://github.com/iakunin/moneta-concurrent-init

What can we do with that problem? Should it be solved here or it'd be better to bug-report in some other project?

iakunin avatar May 10 '20 17:05 iakunin

Thanks for sharing the insight. It could be related to this one https://github.com/JavaMoney/jsr354-ri/issues/331 where the reporter asked to close it, but we could see, if there is some problem with concurrency starting with Java 11 that does not only affect Kubernetes or Spring Boot.

keilw avatar May 10 '20 17:05 keilw

Looks like the same issue to me that we had as well in JavaMoney/jsr354-ri#331.

In your prototype you do the initial call the Moneta within a parallel stream.

Somehow it seems that Spring Boot 2.x jars breaks Moneta SPI with Java 11 and initialization in parallel streams.

ncwoehler avatar May 18 '20 14:05 ncwoehler

I am not that into the OpenJDK thing here I'm afraid, so hope either @otaviojava (who seems to have done something in OpenJDK) might help you with that one. I also pinged @vgrazi who did e.g. https://github.com/vgrazi/java-concurrent-animated a long time ago, but he's officially "Emeritus"(as Spec Lead) but if he had time, of course he'd also be more than welcome to contribute.

keilw avatar May 18 '20 14:05 keilw

Btw, are either of you JCP members at least Associate members? Otherwise it might be tricky with PRs for that. All the mentioned including Victor are JCP members and are or were EG members.

keilw avatar May 18 '20 15:05 keilw

If it's Moneta SPI then I guess it should be in a different repo. I'm not the deepest concurrency guy here, but one problem could be related to the use of MonetaryConfig in moneta, while the preferred approach would be DefaultConfigProvider which at least uses a ConcurrentHashmap under the hood. It's a wild guess but have a look. If that's the case it would be mostly in the RI.

keilw avatar May 18 '20 15:05 keilw

I guess the problem is, in the ServiceProvider implementations ServiceLoader.load method is called with single parameter. Which cause it to use Thread.currentThread().getContextClassLoader(). Which is weirdly in java11 fail to find the services. I tried to copy PriorityAwareServiceProvider and just change that line to ServiceLoader.load(serviceType, MonetaTestApplication.class.getClassLoader() and in the main method's static block call Bootstrap.init(new MyShinyNewServiceProvider()) in the provided project to reproduce the error, and it works pretty well. By the way it solves the Currency Not found exception too.

utkanozyurek avatar Jun 03 '20 22:06 utkanozyurek

Do you think you could create a PR based on those findings?

keilw avatar Jun 03 '20 23:06 keilw

here the PR: https://github.com/JavaMoney/jsr354-ri/pull/333

utkanozyurek avatar Jun 04 '20 09:06 utkanozyurek

If it's possible to upload snapshot somewhere, I can check if it helps in my repo with bug reproduction.

iakunin avatar Jun 04 '20 09:06 iakunin

moneta-core-1.4.1-SNAPSHOT.jar.zip you can try with this jar :)

utkanozyurek avatar Jun 04 '20 14:06 utkanozyurek

Tested with the repository referenced in https://github.com/JavaMoney/jsr354-ri/issues/331. The PR fixes the issue :+1:

ncwoehler avatar Jun 04 '20 15:06 ncwoehler

Thanks a lot, I'll check it tomorrow evening or on the weekend. @utkanozyurek it seems you are not a JCP Member. Would you consider joining the JCP? Everyone else is equally welcome, and although we'll wait for the EC to approve the MR1 before publishing a service update, we should merge this very quickly but from a process point it is better, if authors of a PR also joined the JCP at least on the "Associate" level, which is easiest even for employees of a company.

keilw avatar Jun 04 '20 17:06 keilw

Thanks @keilw , I needed to update the personal information in JCP account before applying for associate membership, it's waiting for JCP PMO review.

utkanozyurek avatar Jun 05 '20 08:06 utkanozyurek

moneta-core-1.4.1-SNAPSHOT.jar.zip you can try with this jar :)

@utkanozyurek problem is not reproduced in my repo anymore. Many thanks to you! :)

iakunin avatar Jun 05 '20 09:06 iakunin