cavaliergopher / grab

A download manager package for Go
BSD 3-Clause "New" or "Revised" License
1.38k stars 151 forks source link

Download is not resumed after killing the application with ctrl + c #44

Closed jadolg closed 4 years ago

jadolg commented 5 years ago

I made an application that uses your lib and when I hit ctrl + c and then execute it again it starts downloading from 0. I'm downloading the same URL on the same path.

cavaliercoder commented 5 years ago

This will happen if you set NoResume=true, if the incomplete file is not flushed to disk, or if the remote server does not support range requests.

Can you share some of your code or the URL you are downloading?

jadolg commented 5 years ago

Hi @cavaliercoder I'm using your lib here https://github.com/jadolg/DockerImageSave/blob/master/cmd/DockerImageSave/download.go It's almost exactly your code sample with just little modifications. And the server is basic GO http server https://github.com/jadolg/DockerImageSave/blob/master/cmd/DockerImageSaveServer/main.go I'll check the capabilities of this server cause I'm not sure it allows range requests.

cavaliercoder commented 5 years ago

Nice! Thanks for sharing.

I can see that your server currently does not support ranged requests. To do so, you would need to explicitly set the Accept-Ranges: bytes header and implement handlers that acknowledge the Range request header.

The http.ServeContent function in Go stdlib implements this for you.

jadolg commented 5 years ago

According to https://lets-go.alexedwards.net/sample/02.08-serving-static-files.html Range requests are fully supported by http.FileServer :thinking:

cavaliercoder commented 5 years ago

Hrmmm... this seems to be correct. FileServer ultimately calls serveContent which implements range requests.

Can you tell me which headers you server is returning for the download requests? $ curl -I <url>.

jadolg commented 5 years ago

curl -i -H "Range: bytes=100-199" http://ddnnss.eu:6060/download/gitlab_gitlab-ce:11.3.0-ce.0.tar.zip
HTTP/1.1 206 Partial Content
Accept-Ranges: bytes
Content-Length: 100
Content-Range: bytes 100-199/515047585
Content-Type: application/zip
Last-Modified: Wed, 26 Sep 2018 14:43:48 GMT
Date: Wed, 26 Sep 2018 20:34:27 GMT

P�R@d��In��4)�IKY4E@@DVYdDQd�U@VEDQE���LK(`�j�����y��s�̙3˙�{f�܉:���k�L�Fg2��6#g�sZ�r111
jadolg commented 5 years ago
$ curl -I http://ddnnss.eu:6060/download/gitlab_gitlab-ce:11.3.0-ce.0.tar.zip                                                                                                                                                                                                 
HTTP/1.1 200 OK                                                                                                                                                                                                                                                               
Accept-Ranges: bytes                                                                                                                                                                                                                                                          
Content-Length: 515047585                                                                                                                                                                                                                                                     
Content-Type: application/zip                                                                                                                                                                                                                                                 
Last-Modified: Wed, 26 Sep 2018 14:43:48 GMT                                                                                                                                                                                                                                  
Date: Thu, 27 Sep 2018 14:16:14 GMT
jadolg commented 5 years ago

Hi, @cavaliercoder have you made any progress with this?

cavaliercoder commented 5 years ago

Not yet sorry. I'm very constrained for time.

cavaliercoder commented 5 years ago

Sorry for the late response. Have you found a solution for this? If not, I'll take another look.

jadolg commented 5 years ago

I was reading your code but couldn't really put too much time to understand the problem, so I'm on the same place :-( I would really appreciate this to be fixed. Sometimes we're working on slow and unstable connections and a really resilient download manager is really helpful on these kind of environment.

jadolg commented 5 years ago

Any news? You can use the context of my application to test (https://github.com/jadolg/DockerImageSave). I'll for sure use this project for a lot more projects because the Internet in Cuba still sucks and we need resilient applications.

cavaliercoder commented 4 years ago

I've tested this extensively using the binary at cmd/grab/main.go and other tests. Unfortunately, I can't reproduce the problem :/

Please feel welcome to reopen the issue if you can produce a test to replicate the problem. Some things to check:

jadolg commented 4 years ago

Hi @cavaliercoder I just wanted to let you know that I'm no longer able to reproduce the problem. I'm not sure what changed though. I think updating all libraries on my project did the trick. Thanks for spending time on it and for this great project :)