I am trying to upload a jar file to an s3 bucket:
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
import software.amazon.awssdk.services.s3.model.S3Exception;
protected boolean uploadToS3(File jarFile, String bucketName, String path) {
PutObjectRequest putJarRequest = PutObjectRequest.builder()
.bucket(bucketName)
.key(path)
.build();
logger.info("Trying to upload jar {} to {}, on bucket: s3 bucket {}", jarFile.getName(), path, bucketName);
try (S3Client s3Client = S3Client.builder().credentialsProvider(DefaultCredentialsProvider.create()).build()) {
return s3Client.putObject(putJarRequest, Path.of(jarFile.toURI())) != null;
} catch (S3Exception e) {
logger.error("Exception caught while trying to upload jar:");
logger.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
}
This works fine but I intermittently get the following error:
Caused by: java.lang.IllegalStateException: Connection pool shut down
at org.apache.http.util.Asserts.check(Asserts.java:34)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.requestConnection(PoolingHttpClientConnectionManager.java:269)
at software.amazon.awssdk.http.apache.internal.conn.ClientConnectionManagerFactory$DelegatingHttpClientConnectionManager.requestConnection(ClientConnectionManagerFactory.java:75)
at software.amazon.awssdk.http.apache.internal.conn.ClientConnectionManagerFactory$InstrumentedHttpClientConnectionManager.requestConnection(ClientConnectionManagerFactory.java:57)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:176)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
The s3Client
is closed every time i make a request, it implements Autocloseable and is placed within a try with resource block, so no issues there.
Does anyone has any idea what is happening here?