Closed lukaszkorecki closed 4 years ago
@lukaszkorecki Maybe parsing headers via a temporary file isn't the best idea ever. This was done because when parsing the headers from the same stream as the response with the --include
option, there is no reliable way to detect when the headers end and the response body starts.
Could it be that we have to call .destroy
on the curl process to free up these resources?
I can reproduce the problem locally with this script:
(require '[babashka.curl :as curl])
(while true
(Thread/sleep 1000)
(let [resp (curl/get "https://www.clojure.org")]
(:body resp)
(.destroy (:process resp))) ;; this is not helping
)
Note that this script doesn't exhibit the problem:
(while true
(Thread/sleep 1000)
(let [f (java.io.File/createTempFile "babashka.curl" ".headers")]
(spit f "foo")
(.delete f)))
Yeah, the process included in the response map was my first hint - and I did try the .destroy
method on it and it didn't help. I wonder if it needs to be called before deleting the tempfile?
@lukaszkorecki I'll do some testing...
Meanwhile you can poll your endpoint using something like this:
(clojure.java.shell/sh "curl" "https://www.clojure.org")))
or use HttpURLConnection
as follows:
The library https://github.com/borkdude/clj-http-lite is based around HttpURLConnection
and this library can also be used with babashka.
So far I've found that running with the JVM (instead of GraalVM) has the same behavior so at least it's not a GraalVM problem.
@lukaszkorecki Found the culprit!
(defn- read-headers [^File header-file]
(line-seq (io/reader header-file)))
This leaves the file handle open. Will fix ASAP.
@borkdude oh, nice! Thank you 🎉
@lukaszkorecki Will publish a new version of bb. Thanks for finding this.
@borkdude Thank you for creating BB - finally it feels like we have a viable Clojure for small tasks :-)
Thank you. Released: https://github.com/borkdude/babashka/releases/tag/v0.0.86
I wrote a small daemon which monitor's ECS metadata endpoint and reports basic Docker stats via Statsd protocol. So far soo good! It runs on a 10s interval - so every 10s it will use
babashka.curl
to poll the endpoint. I've noticed this morning that at some point we stopped receiving metrics from our services. I've looked into the logs and this line popped up:I looked at the source and it looks like despite calling
.delete
on the temp file, file handles are not freed. I wrote a simple babashka script which polls a local web server in a very tight loop (1s). Then checked the file handles opened by the process:Of course on exit all file handles are freed - not sure what the fix is, as the Java doc for File doesn't indicate any other way of freeing the handles.