This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-11-02
Channels
- # announcements (3)
- # aws (8)
- # babashka (87)
- # babashka-sci-dev (3)
- # beginners (34)
- # calva (35)
- # clerk (2)
- # clj-commons (47)
- # cljdoc (10)
- # cljs-dev (21)
- # clojure (19)
- # clojure-android (1)
- # clojure-austin (2)
- # clojure-europe (30)
- # clojure-nl (1)
- # clojure-norway (67)
- # clojure-uk (9)
- # clojuredesign-podcast (7)
- # clojurescript (24)
- # code-reviews (20)
- # cursive (6)
- # datomic (12)
- # emacs (14)
- # events (1)
- # fulcro (7)
- # gratitude (1)
- # hoplon (8)
- # hyperfiddle (23)
- # juxt (22)
- # meander (11)
- # nyc (3)
- # overtone (2)
- # podcasts-discuss (1)
- # reagent (3)
- # releases (1)
- # sci (27)
- # shadow-cljs (73)
- # squint (4)
- # thejaloniki (3)
- # xtdb (7)
Heyo! I have a concurrency exception that only occurs while using babashka and not jvm Clojure when trying to query AWS-resources in parallel using https://github.com/grzm/awyeah-api. I have a bit of repro-code and a stack-trace, should I dump the stack trace in ๐งต as a start, or do you want an issue on GitHub?
Is it possible to make the smallest repro possible, preferably even without the awyeah-api lib?
If it's an issue with awyeah-api I suggest creating an issue there, but if you can demonstrate it's a bb issue, please make an issue with bb
That's the kicker; it wasn't obvious to me from the stack trace whether the exception originated from the library or not. It doesn't make it easier that it only fails for a few elements of the collection I'm processing either. Anyway, the reason I started in this channel was because I wasn't able to reproduce the error on JVM, so I thought maybe you could deduce something from the stack trace
This only happens for a few elements of the collection. I have 47 queues, and when fetching attributes for each queue in parallel, like 1-10 of them fail with that error. On JVM, none of them produce that error
I've seen a similar error in httpkit with native-image. this was an issue with SimpleDateFormat or something. I migrated that to java.time and the error went away, let's check if awyeah is using this old stuff
https://github.com/http-kit/http-kit/commit/b45725fb64c1025c305632a6d6d869ccc447b4a5 here I got the same bug
check this issue: https://github.com/http-kit/http-kit/issues/543 are you providing a virtual thread pool or something?
The error seems to happen around clojure.data.xml$parse
so perhaps it's possible to make a repro using that
I'm trying to repro it like this:
$ bb -e '(clojure.core.async/<!! (clojure.core.async/go (clojure.data.xml/parse (java.io.ByteArrayInputStream. (.getBytes "<a></a>")))))'
#xml/element{:tag :a}
Perhaps it would help you if executed a dummy XML read like the above in your program before doing anything with awyeah
A workaround for your problem would be I think:
(alter-var-root #'clojure.core.async/go (constantly @#'clojure.core.async/thread))
Sorry, was eating! I got this error using the Java Executors stuff with a fixed thread pool like this
(ns sqs.lib.repro
(:require [com.grzm.awyeah.client.api :as aws])
(:import [java.util.concurrent ExecutorService Executors Future]))
(defn jxmap
([f coll] (jxmap f coll 100))
([f coll concurrency]
(let [executor (Executors/newFixedThreadPool concurrency)
tasks (mapv #(fn [] (f %)) coll)]
(->> (.invokeAll ^ExecutorService executor tasks)
(map #(.get ^Future %))))))
then something like
(def attributes (jxmap #(aws/invoke sqs-client {:op :GetQueueAttributes
:request {:QueueUrl %
:AttributeNames ["All"]}}) queues 100))
where queues is a vec of stringstry this as a workaround:
(alter-var-root #'clojure.core.async/go (constantly @#'clojure.core.async/thread))
you can use this:
BABASHKA_PRELOADS="(alter-var-root #'clojure.core.async/go (constantly @#'clojure.core.async/thread))"
I'll upgrade native image to 21.0.0.1 and then you can also try it without that patch
I tried it now by evaluating (alter-var-root #'clojure.core.async/go (constantly @#'clojure.core.async/thread))
, then evaluating the async code. I still get the same problem here, is there a difference between evaluating it in the repl, and providing the env var?
That seems to have done the trick!
of 47 queues, there were 0 failures
of 47 queues, there were 0 failures
of 47 queues, there were 0 failures
of 47 queues, there were 0 failures
of 47 queues, there were 0 failures
of 47 queues, there were 0 failures
of 47 queues, there were 0 failures
no, it's a bb issue, feel free to post an issue, I'm working on a fix (by upgrading graalvm). Also please post the workaround in the issue so people can find it later
alright, try this:
bash <(curl ) --dev-build --dir /tmp
and then run your program with /tmp/bb
Make sure you unset the env variable. Use a new terminal just to be sure you haven't still set it.Looking good :star-struck:
of 47 queues, there were 0 failures
of 47 queues, there were 0 failures
of 47 queues, there were 0 failures
of 47 queues, there were 0 failures
of 47 queues, there were 0 failures
of 47 queues, there were 0 failures
of 47 queues, there were 0 failures
of 47 queues, there were 0 failures
of 47 queues, there were 0 failures
of 47 queues, there were 0 failures
of 47 queues, there were 0 failures
of 47 queues, there were 0 failures
of 47 queues, there were 0 failures
of 47 queues, there were 0 failures
What was the fix? So many branches. Saw the bump of graalvm here https://github.com/babashka/babashka/commits/21_0_0_1, but was that all you needed, and how did you know?
Seriously, amazing catch, thanks so much, I've had this problem for weeks and thought I was just getting increasingly bad at clojure
hmm, actually, this is weird. the version you installed wasn't the version from my branch but from the master branch. So I'm puzzled why it works for you
it's coming from here: https://github.com/babashka/babashka-dev-builds/releases/tag/v1.3.186-SNAPSHOT
I haven't upgraded homebrew-bb for those days, and just did it during lunchtime now. Will try again with the homebrew-version and see
anyway I can repro it locally using an example I posted in the issue and I can confirm that it works with 21.0.1 which I have installed locally
Just seen that https://justine.lol/cosmo3/ has been released (TL;DR compilation toolchain for "actually portable executables"), wonder if it's worth hooking it up to graal, can you specify other compiler toolchains?
Posting here because it would be cool to have a single bb
that actually runs the same everywhere
thanks for sharing, I'll ask in the native-image channel on native-image if they have heard of this
You can follow this issue: https://github.com/oracle/graal/issues/4854
https://clojurians.slack.com/archives/C06MAR553/p1698931227405429
I don't think this is a babashka problem, but I feel it's likely that someone here will know the solution ๐.
Why does curl/get ... {:as :stream}
download into ram first?
(let [request (curl/get "myurl" {:as :stream})]
(with-open [body (:body request)]
(println (type body))
(aws/invoke s3 {:op :PutObject
:request {:Bucket "..."
:Key "..."
:ContentType (get-in request [:headers "content-type"])
:ContentLength (Integer. (get-in request [:headers "content-length"] 0))
:Body body}})))
This creates the network behavior in the attached screenshot. Is there any way to reduce the buffer of the input stream to prevent loading the whole file into ram? I suppose the only other option would be to download the file direct to disk, then move that to s3. i.e. stream network -> disk, disk -> s3, but that seems quite wasteful.