-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Cannot retry when using :as :stream
option
#38
Comments
Thanks, I'll have a look soon. In the newest bb we now also support the JDK 11 Http Client. And otherwise you could shell out to curl directly as a workaround. |
@bhb I can't repro this. I added the options
|
@bhb Could you try the above too to see if the same happens for you, with the recent commit on master? |
@borkdude What do you see if you add
If I adapt your code above to add First, I tried the version packaged in Babashka: ;; bb --version
;; babashka v0.6.1
(require '[babashka.curl :as curl])
(curl/get "https://httpstat.us/500" {:as :stream :err :inherit :silent false :raw-args ["--retry" "3"]}) Then I tried to include the latest (require '[babashka.deps :as deps])
(deps/add-deps '{:deps {io.github.babashka/babashka.curl {:git/sha "75389c5ae0a084b33529190d654b71e021239fa4"}}})
(require '[babashka.curl :as curl])
(curl/get "https://httpstat.us/500" {:as :stream :raw-args ["--retry" "3"] :debug true}) In both cases, I get a 500 immediately and I don't see the output you posted above. |
@bhb I see. I think the problem was that bb.curl throws as soon as it discovers that the status code is 500-ish. Can you try your request with |
@borkdude In my tests, using To summarize, here are my results (require '[babashka.deps :as deps])
(deps/add-deps '{:deps {io.github.babashka/babashka.curl {:git/sha "75389c5ae0a084b33529190d654b71e021239fa4"}}})
(require '[babashka.curl :as curl])
;; With no ':as :stream', this will retry 3 times, then throw (as expected)
(curl/get "https://httpstat.us/500" {:err :inherit
:silent false
:raw-args ["--retry" "3"]})
;; With no ':as :stream' and ':throw false' this will retry 3 times, then return map that contains status code (as expected)
(curl/get "https://httpstat.us/500" {:throw false
:err :inherit
:silent false
:raw-args ["--retry" "3"]})
;;; Unexpected behavior below
;; With ':as :stream', this immediately throws a 500 without retry
(curl/get "https://httpstat.us/500" {:as :stream
:err :inherit
:silent false
:raw-args ["--retry" "3"]})
;; With ':as :stream' and ':throw false', this immmediately returns a map with a status code (without retrying)
(curl/get "https://httpstat.us/500" {:as :stream
:throw false
:err :inherit
:silent false
:raw-args ["--retry" "3"]})
|
I would say the but-last expression is unexpected but an edge case: the Then with the last expression. It returns immediately, because this is what If you which I think indicates that there were three retries. But perhaps this is not your use case and you just want a blocking request and want the bytes as a result? Could you clarify more context around your use case? Perhaps an easier way for you to work with this is call curl manually using (def stream (:out (babashka.process/process "curl https://avatars.githubusercontent.com/u/64927540?s=400&u=644e8997a671220cb729260cfbf678d9cfddaa1b&v=4 --retry 3" {:err :inherit})))
(io/copy stream (io/file "icon.png")) But let me know if you want a blocking bytes call because this is pretty easy to support with |
Great question - I probably should have started with this 😄 . I am using Unfortunately sometimes I get transient errors like 500s or 503s when I try to download the file. The two possible outcomes for my script are:
So yes, ideally there would be a blocking call that gets the entire file but will also allow me to pass I've worked around this by writing my own retry logic on top of
That's a good idea, I can definitely do that! |
Hm, maybe that's exactly what I need. The file I'm downloading is gzipped json, so I can't do anything meaningful with it until it's completely downloaded. I must have missed this option previously. My mistake! |
@bhb That option isn't yet there, it was a proposal. Will respond on the rest soon. |
@bhb OK, after reading your feedback, I think we can just support |
@borkdude That sounds great. Thanks so much! |
I implemented the |
The text was updated successfully, but these errors were encountered: