Fork me on GitHub
#graalvm
<
2020-07-24
>
jose09:07:08

I'm doing a http request with the jdk11 http client, but when I try to compile it, I got an error from the native-image command (`Error: No instances of http://javax.net.ssl.SSLContext are allowed in the image heap as this class should be initialized at image runtime`) I'm calling the same methods hato calls, I guess I'm missing something on my native-image configuration. @borkdude Since you mentioned you were able to compile a project with your hato-native fork, do you still have the configuration you used?

borkdude09:07:06

and compiled that with babashka. you probably need to enable ssl using a flag. let me check

jose09:07:09

@borkdude Thanks for sharing it, I already had that options, I guess it has something to do with the --initialize-at-run-time option

borkdude09:07:53

could try to initialize that class at runtime. unfortunately I threw away the hato branch of babashka

borkdude09:07:57

Recently there has been a PR to clj-http which presumably also solves this problem, could also look at that

borkdude09:07:59

or use clj-http-lite, babashka.curl, etc. but I guess you already considered those options

jose09:07:51

Thanks, I'll let you if I can find a solution, I already tried to initialize that class at run time, but still get the error. Most probably I'll end using clj-http-lite, but I wanted to try to find a solution for jdk11 client

borkdude09:07:45

hmm, is there a way to recover thrown away branches? let me check if I have it still on my computer...

borkdude09:07:44

got it!

🎉 3
borkdude09:07:35

and I think that worked at the time.

borkdude09:07:40

I don't see anything special in the compile script

jose09:07:52

me neither, but thanks for pushing the branch, I just cloned it locally, in case you want to delete it again. Maybe has something to do with the graalvm version, I'm going to investigate a bit to see what I can find

borkdude09:07:47

you can clone it like:

git clone -b hato-jdk11  --recursive
Note it has submodules

borkdude09:07:00

I'll try to compile it locally to see if it still works

borkdude10:07:48

That was before clojure 1.10.2-alpha1. I'm getting the unbalanced monitor problem with that branch locally now. How did we get things done back then ;)

borkdude10:07:53

@jlle This works for me now, after running script/compile:

./bb -e '(hato.client/get "")'

borkdude10:07:05

I pushed a fix by bumping the Clojure version

borkdude10:07:06

compiled with GraalVM 20.1.0 jvm11

jose10:07:40

just using the compile script, right?

borkdude10:07:46

yes, script/compile

jose10:07:02

I'm trying it

borkdude10:07:15

if it's slow (> 5 minutes) try bumping the available memory:

export BABASHKA_XMX="-J-Xmx8g"

jose10:07:01

it just finished 🙂

jose10:07:18

yes, it works locally for me too

jose10:07:07

now I need to find what is different on my project, thanks a lot @borkdude

borkdude10:07:22

you can try compiling your GraalVM project with my hato fork

jose10:07:35

makes sense, I'll try that

borkdude10:07:15

hmm, wait, you didn't use hato, just the JDK 11 client right

jose10:07:56

yes, in my project I'm using jdk11 client directly

jose10:07:52

uhm, now I'm confused, I just added your hato fork to my project, and I can compile it and make requests. But I get an error compiling it if I use the jdk11 client directly. I'm just looking again to how hato makes the request, but I don't see any difference with my code

borkdude10:07:14

interesting

jose11:07:37

I found the reason, I was declaring my HttpClient globally, like this:

(def client (-> (HttpClient/newBuilder)
                (.build)))
If I put the client creation in a let block inside a function, or wrap it in a delay, I can compile it. But no idea why is that

borkdude11:07:29

I was suspecting something like that

borkdude11:07:53

compile time vs runtime initialization

jose11:07:04

I also get the error with your fork if I create a hato client in advance:

(def c (hato/build-http-client {}))
(hc/get "" {:http-client c})

borkdude11:07:31

thanks for figuring it out.

jose11:07:58

thanks for your help 🙂