-
Notifications
You must be signed in to change notification settings - Fork 241
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
Prevent http/get stream from being closed [question] #500
Comments
Small update: even with idle-time, I still cannot download a file in repl. This time, I almost finished reading the stream. The exception was saying |
upd: so far, I figured out with
The |
@igrishaev So, does it work or you need any help on this? |
@kachayev it works because I switched to |
@igrishaev Is there any reproducible code that I can run? It's really hard to tell anything w/o looking into specific details. |
@kachayev here is a sample of code that has been failing on Friday. Today at home, it works fine so I cannot reproduce the exception I wrote about. I'm not against closing that issue. But before I do this, could you please ensure it works on your machine? Here is an example where I restream a file into S3. Just in case you don't time to deal with AWS credentials, please use the second snippet. (require '[amazonica.aws.s3 :as s3])
(require '[aleph.http :as http])
(require '[manifold.deferred :as d])
(def url
"http://exoscale-packer-images.ppsos-ch-dk-2.exo.io/exoscale-debian-stretch-2019-03-27-6cf902.qcow2")
(def len 1418264736)
(def creds {:access-key "................"
:secret-key "..................."
:endpoint "us-east-1"})
(defn example
[]
(let [{:keys [body]} @(http/get url)
request {:bucket-name "uploadedfiles"
:key "test"
:input-stream body
:metadata {:content-length len}
:canned-acl :public-read}]
(s3/put-object creds request)))
(example) This is the second example. Here, I just consume the stream in a cycle. The ;; the same imports...
;; [com.amazonaws/aws-java-sdk-core "1.11.528"]
(import 'com.amazonaws.util.LengthCheckInputStream)
(defn example
[]
@(->
(http/get url)
(d/chain
(fn [result]
(let [{:keys [body]} result
stream (new LengthCheckInputStream body len false)
buffer (byte-array (* 1024 1024 4))]
(while (not= -1 (.read ^LengthCheckInputStream stream buffer))))))))
(example) |
#'user/example
user=> (example)
nil The last example works on my machine. I can't run the first one as I don't have any available S3 creds right now. The only question I have... are you sure that |
I also couldn't reproduce it again. Closing, maybe will investigate more. |
What I've got to do is to get a file stream from a remote HTTP server and then upload that stream into AWS S3.
I query a URL with
http/get
, parse Content-Length header to know the file size and pass that into AWS PutObjectRequest as follows:The problem is, in the middle of the upload AWS fails with an error like:
There is a special
com.amazonaws.util.LengthCheckInputStream
class that counts a number of bytes read from a stream. In case the number differs from the provided content-length, it throws an error.I may guess, the reason for that is the connection pool closes HTTP connection before the stream has been read completely. I wonder what would be the best strategy to keep the connection alive?
Right now, I passed a huge idle timeout:
and so far it goes well. Is there another right way to do that?
The text was updated successfully, but these errors were encountered: