Skip to content
Advertisement

How should I handle “java.net.SocketException: Connection reset” in multithread AWS S3 file upload?

I have a ThreadPoolExecutorService to which I’m submitting runnable jobs that are uploading large (1-2 GB) files to Amazon’s S3 file system, using the AWS Java SDK. Occasionally one of my worker threads will report a java.net.SocketException with “Connection reset” as the cause and then die.

AWS doesn’t use checked exceptions so I actually can’t catch SocketException directly—it must be wrapped somehow. My question is how I should deal with this problem so I can retry any problematic uploads and increase the reliability of my program.

Would the Multipart Upload API be more reliable?

Is there some exception I can reliably catch to enable retries?

Here’s the stack trace. The com.example.* code is mine. Basically what the DataProcessorAWS call does is call putObject(String bucketName, String key, File file) on an instance of AmazonS3Client that’s shared across threads.

JavaScript

Advertisement

Answer

The javadoc says that putObject() throws AmazonClientException when this kind of error occurs. AmazonClientException has a method called isRetryable(), you can try with that.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement