title: Java.net.SocketException: Connection reset when reading file from S3
body: <p>I'm trying to read some files from S3 and do some processing on each file. I can get through some files, but I keep getting <strong>Java.net.SocketException: Connection reset</strong> at the same line in a particular file during processing. The file in question should be ok though because I can process it locally using the same class and method (conversionUtils.convert()).</p>
  
  <p>Service class:</p>
  
  <pre><code>public class FileService {
  
    @Inject
    private S3Utils s3utils;
  
    private ConversionUtils conversionUtils = new ConversionUtils();
  
    public void processFile() {
      List&lt;S3ObjectSummary&gt; files = s3utils.getAllFiles();
      List&lt;S3Object&gt; unprocessedFiles = s3utils.getUnprocessedFiles(files);
  
      for(S3Object file: unprocessedFiles) {
        InputStream content = file.getObjectContent();
        List&lt;Record&gt; records = conversionUtils.convert(content); //Exception thrown here
      }
    }
  }
  </code></pre>
  
  <p>S3Utils class: </p>
  
  <pre><code>@Component
  public class S3utils {
    @Inject AmazonS3 amazonS3;
  
    public List&lt;S3ObjectSummary&gt; getAllFiles() {
      ListObjectsV2Request request = new ListObjectsV2Request().withBucketName('something').withPrefix('some_prefix');
      ListObjectsV2Result result = amazonS3.listObjectsV2(request);;
  
      return result.getObjectSummaries();
    }
  
    public List&lt;S3Object&gt; getUnprocessedFiles(List&lt;S3ObjectSummary&gt; files) {
      //do some filtering here
  
      List&lt;S3Object&gt; unprocessedFiles = new ArrayList&lt;&gt;();
      for (S3ObjectSummary summary : filteredSummaries) {
        S3Object s3Object = amazonS3.getObject(new GetObjectRequest(summary.getBucketName(), summary.getKey()));
        unprocessedFiles.add(S3Object);
      }
      return unprocessedFiles;
    }
  }
  </code></pre>
  
  <p>Config class:</p>
  
  <pre><code>@Configuration
  public class Config {
    @Bean
    public AmazonS3 amazonS3() {
      return AmazonS3ClientBuilder.standard().withCredentials(new DefaultAWSCredentialsProviderChain()).build();
    }
  }
  </code></pre>
  
  <p>I've read some other threads with similar errors where the issue was that the AmazonS3 client was being garbage collected, and therefore closing the stream, but I'm wondering if that's the case here. Any ideas on what the issue is? Thanks.</p>