dakrone / clj-http

An idiomatic clojure http client wrapping the apache client. Officially supported version.
http://clojars.org/clj-http
MIT License
1.78k stars 410 forks source link

AOT issues with clj_http.headers.HeaderMap #638

Open pesterhazy opened 1 year ago

pesterhazy commented 1 year ago

I'm following the guide for using AOT. This works ... except for clj-http.

The error I'm getting is not when compiling but when loading the compiled classes (rather than clj files):

Execution error (ClassNotFoundException) at jdk.internal.loader.BuiltinClassLoader/loadClass (BuiltinClassLoader.java:641).
clj_http.headers.HeaderMap

When I rm -rf classes/clj_http, it works again.

Unfortunately I couldn't come up with a simple repro case - when I tried it outside of the main app, it worked. Not sure why - race condition?

I suspect (but cannot prove) that the AOT incompatibility is due to the use of potemkin.

There's an earlier report from 2016, but I'm not using Leiningen https://clojurians.slack.com/archives/C0AB48493/p1469153573000034

clj-http/clj-http 3.12.3
potemkin/potemkin 0.4.5
pesterhazy commented 1 year ago

BTW uberjars work fine - the issue happens only when AOT-compiling for development

pesterhazy commented 1 year ago

After some investigations, here's what I learned:

• Part of the problem seems to be loading namespaces in user.clj. After stopping to load stuff in user.clj, the problem went away for me (this explains why lein uberjar etc doesn't have the problem)

• Generally what seems to be happening is this: I'm loading clj-http and then compiling it. "Something is loading clj-http before you do the aot compilation, and on the second loading (for aot) potemkins type definition stuff no-ops, so the class doesn't get written to disk"

More discussion here: https://clojurians.slack.com/archives/C03S1KBA2/p1697468125926469

This still seems like a wrinkle in clj-http, though maybe not a bug (maybe in potemkin?)

dakrone commented 1 year ago

Something is loading clj-http before you do the aot compilation

Could this be something internal to leiningen itself that's loading clj-http?

pesterhazy commented 1 year ago

I'm using tools.deps for this report. I'm pretty sure the problem is because the lib was loaded in user.clj, then compiled

On Tue 24. Oct 2023 at 01:10, Lee Hinman @.***> wrote:

Something is loading clj-http before you do the aot compilation

Could this be something internal to leiningen itself that's loading clj-http?

— Reply to this email directly, view it on GitHub https://github.com/dakrone/clj-http/issues/638#issuecomment-1776167738, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAZ6WEHT3YVQEWFYEVZ6IDYA32N3AVCNFSM6AAAAAA6CKWF62VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZWGE3DONZTHA . You are receiving this because you authored the thread.Message ID: @.***>