download-with-webtorrent-button
download-with-webtorrent-button copied to clipboard
Button does not transition to "Ready" state
(forked from #1)
@hisener: I've started the downloading on the demo page and after some time, the result is:
And I could not download the file.
Normally it hangs at 100% a few seconds while it converts the download to a Blob, and should change from " - 100% \n Downloading (N peers)" to say " - Ready \n Click to download". Hopefully it's just a simple mistake and I can fix it quickly!
Observation: happens on both HTTP and HTTPS.
Alright. This took some sleuthing. Because there's some weird behavior, like if you open another browser and download it, suddenly it will fix itself and switch to "- Ready" state. And it doesn't happen in Firefox, but does in Chrome. But not always in Chrome. (I thought it was a race condition for a long time.)
What it is, is WebTorrent makes lots of tiny (16KB) requests to the webSeed. If there are no other users downloading that webSeed is its only peer. If one of those requests fail, it assumes that the webSeed "peer" does not have that "piece". Or maybe it assumes that it successfully got the piece, I'm not sure. The net result is you have 999 or 1000 pieces downloaded1 but no way to get that last piece. What's missing is some way to retry that piece request. I might have to punt this one to @feross... I'm also not sure what exactly the error is. It's not a 404 or a timeout... it just says "canceled":
It may be as simple as increasing the timeout of something somewhere.
Edit: If I manually re-add the webSeed by doing torrent.addWebSeed('https://cors-buster.now.sh/?href=https%3A%2F%2Fnodejs.org%2Fdist%2Fv6.10.2%2Fnode-v6.10.2-linux-x64.tar.xz')
then it will download that piece and switch to "- Ready".
1The progress bar says 100% because of rounding - I'll change it to use floor instead of round.
@heisner @feross I added a 2nd webseed... so if WebTorrent worked like I thought, you'd now have to get two get two requests for the exact same chunk to two different sources to get canceled. However, I'm still reliably reproducing this error... no request for the failed chunk gets attempted. I feel like this is ultimately going to be fixed somewhere in WebTorrent's code....