Download the whole file #jv8


I implemented multi-threaded approach to download the file, and noticed that peer connection is very unstable making test runs unable to reproduce.

  • with the same code some time I pass tests, sometime I don’t.
  • all the peers would refuse connections even after multiple retries. And when they do, test times out.
  • sometime test asks you to download the file with 3 pieces, sometimes 12. The code that can pass with 3 pieces will fail when trying to download 12 pieces.
  • Earlier “accepted” solutions by other members also fail tests sometime. Sometimes, they pass the test.

@sarp
Please advise How to proceed here.

@rahul1990gupta can you confirm whether you’re making multiple connections to the same peer? If so, these will likely get rejected (we use publicly-hosted seeders for this stage, so can’t provide friendly error messages). As long as you’re only making one connection per peer you should be fine.

We have E2E tests that run against these peers every 10 minutes and they hardly ever fail: Workflow runs · codecrafters-io/bittorrent-test-tracker · GitHub.

If you’d like to test whether it’s connection instability, you could try running my code here: GitHub - rohitpaulk/codecrafters-bittorrent-ruby. I had the same instability problem when I was making multiple connections per peer, and it went away after switching to one connection per peer.

(You can still implement parallelism per connection by requesting multiple pieces at once)

Thanks @rohitpaulk for your response.

I was trying to make one connection per host. And upon failing was retrying with the same host. Sometime it connected, sometime it didn’t. Maybe that’s how networking works. :man_shrugging:
One should write code expecting that network connections will fail.

Anyway I was able to pass the tests for this stage after trying a few times.

Thanks for the help!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.