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

Unable to close org.postgresql.jdbc.PgConnection classes with BABASHKA_FEATURE_POSTGRESQL enabled #1344

Open
neuromantik33 opened this issue Aug 23, 2022 · 3 comments

Comments

@neuromantik33
Copy link

version

$ git status
HEAD detached at v0.9.161
nothing to commit, working tree clean

platform

$ uname -a
Linux drnick-xps-15-9500 5.15.0-46-generic #49~20.04.1-Ubuntu SMP Thu Aug 4 19:15:44 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

problem
When using a compiled babashka binary with the BABASHKA_FEATURE_POSTGRESQL and BABASHKA_FEATURE_JDBC features set to true, I'm unable to cleanup resources using with-open. I haven't tested if using the pod produces the same behavior.
repro

$ docker run --name db -tid -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres postgres:13
4dd656b248825c7b3c5103f075277d0db968f88705a5211b3defe24f5ead5376
$ bb -e '
> (let [ds (jdbc/get-datasource {:dbtype "postgres" :host "localhost" :port 5432})]
>   (try
>     (with-open [conn (jdbc/get-connection ds {:user "postgres" :password "postgres"})]
>       (println "result:" (jdbc/execute! conn ["SELECT 1"])))
>     (catch Throwable t
>       (println "context:" (ex-data t))
>       (throw t))))'
result: [{:?column? 1}]
context: {:type :sci/error, :line nil, :column nil, :file <expr>}
----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Method close on class org.postgresql.jdbc.PgConnection not allowed!

expected behavior
No error should occur.

@borkdude
Copy link
Collaborator

We'll need to add extra reflection info for the BABASHKA_FEATURE_POSTGRESQL flag for this class.

@neuromantik33
Copy link
Author

I'll gladly work on it since I seem to be the only one using bb for my postgres sql purposes :) Is there any references you might be able to share before I jump right into Clojure Graalvm goodness?

@lispyclouds
Copy link
Member

Hey @neuromantik33 I could try to point you to some of the files and implementation details, hopefully that helps you get started! I'm not sure how familiar are you with all the bb and graal things so hopefully I can be helpful (I'm a bit shaky on the config too maybe @borkdude can verify this once? 😅):

  • So the issue is the .close method isn't allowed on the class org.postgresql.jdbc.PgConnection as GraalVM needs to know of all methods we may reflect and invoke in a native image as is the common case in Clojure. It uses a config for it.
  • As you can imagine in bb, this could get really big, so we use this piece of code to generate the thing. Since this is code, we can build it up conditionally specially for feature flags.
  • For this issue, we need to add this class here using a similar condition like this
  • That should open up all the public methods on that class and when you compile it now, it should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants