title: Why do downloaded files randomly become corrupted and/or incomplete when using Poco Libs?
body: <p>I've written a simple application utilizing Pocos HTTP library. The application downloads a file from a given source, decrypts it and then uploads it to S3. There are thousands of files that need to be processed in this manner and they have to be finished at most 7 days from when they appeared on the source server. To avoid the headache of threading my app, I decided to just fire up multiple processes of the app (upwards of 16).</p>
  
  <p>The problem I'm running into is that some of the files randomly fail to completely download or they fail to decrypt, most likely because of a corrupted file.</p>
  
  <p>I ran a single instance of the app in visual studio debugger and let it run for 48hrs and it downloaded close to 1200 files. Not a single error. No incomplete downloads and no bad decrypts. But as soon as I fire up more processes (usually anything over 4) of the app, I start getting the errors reported above.</p>
  
  <p>I'm not sure if Poco is doing something weird or Windows has a bug and I'm stumped on how to verify that network contention is the issue and how to resolve it (obviously load balancing, but there doesn't appear a way to limit the app to use % of bandwidth.</p>
  
  <p>Here's the download code I'm using:</p>
  
  <pre><code>URI uri(DownloadRequestURL);
  HTTPClientSession session(uri.getHost(), uri.getPort());
  HTTPRequest req(HTTPRequest::HTTP_GET, DownloadRequestURL, HTTPMessage::HTTP_1_1);
  session.setKeepAlive(true);
  
  HTTPResponse response;
  istream* fileStream;
  
  try
  {
      session.sendRequest(req);
  
  
      fileStream = &amp;session.receiveResponse(response);
  }
  catch (NetException&amp; exc)
  {
      return false;
  }
  catch (...)
  {
      return false;
  }
  
  
  HTTPResponse::HTTPStatus status = response.getStatus();
  if (status != HTTPResponse::HTTPStatus::HTTP_OK)
  {
      return false;
  }
  
  ofstream encryptedFile(Filename, std::ios::out | std::ios::binary);
  
  unsigned long long BytesDowned = StreamCopier::copyStream64(*fileStream, encryptedFile);
  
  encryptedFile.close();
  </code></pre>