Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SdkClientException: Unable to execute HTTP request: Connection reset

I'm trying to upload file to AWS s3 bucket. I'm continuously getting this exception "SdkClientException: Unable to execute HTTP request: Connection reset".

I'm trying to upload by inputstream

AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                .withRegion(Regions.US_EAST_2)
                .withCredentials(new AWSStaticCredentialsProvider(cred))
                .build();
        try {

            ObjectMetadata metadata = new ObjectMetadata();
            metadata.setContentLength(bytesArray.length);
            metadata.setContentType("text/csv");
            s3Client.putObject(new PutObjectRequest(appConfig.getBucketName(), fileName, inStream, metadata).withCannedAcl(CannedAccessControlList.PublicRead));
        }
    ----

Below is the exception in detail. What could be the reason? My S3 bucket has IAM user with S3 full access policy. Is this issue related to network or any other settings?

com.amazonaws.SdkClientException: Unable to execute HTTP request: Connection reset
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleRetryableException(AmazonHttpClient.java:1136)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1082)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:745)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:719)
-------
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:209)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
    at sun.security.ssl.InputRecord.read(InputRecord.java:503)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:396)
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:355)
    at com.amazonaws.http.conn.ssl.SdkTLSSocketFactory.connectSocket(SdkTLSSocketFactory.java:142)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142
like image 922
somspeaks Avatar asked Sep 20 '18 23:09

somspeaks


1 Answers

I found it is occurring due to the firewall. If you set logging.level.com.amazonaws at DEBUG then it will show SSL handshake failing.

like image 168
somspeaks Avatar answered Sep 23 '22 01:09

somspeaks