gnodet commented on code in PR #27672:
URL: https://github.com/apache/camel/pull/27672#discussion_r4240515452
##########
components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Consumer.java:
##########
@@ -124,23 +125,19 @@ protected int poll() throws Exception {
if (!doneFileCheckPasses(bucketName, doneFileName)) {
exchanges = new LinkedList<>();
} else if (fileName != null) {
- LOG.trace("Getting object in bucket [{}] with file name [{}]...",
bucketName, fileName);
-
- GetObjectRequest.Builder getRequest =
GetObjectRequest.builder().bucket(bucketName).key(fileName);
- if (getConfiguration().isUseCustomerKey()) {
- if
(ObjectHelper.isNotEmpty(getConfiguration().getCustomerKeyId())) {
-
getRequest.sseCustomerKey(getConfiguration().getCustomerKeyId());
- }
- if
(ObjectHelper.isNotEmpty(getConfiguration().getCustomerKeyMD5())) {
-
getRequest.sseCustomerKeyMD5(getConfiguration().getCustomerKeyMD5());
- }
- if
(ObjectHelper.isNotEmpty(getConfiguration().getCustomerAlgorithm())) {
-
getRequest.sseCustomerAlgorithm(getConfiguration().getCustomerAlgorithm());
+ // check if file is already in progress (add false = duplicate
file)
+ if (!getEndpoint().getInProgressRepository().add(fileName)) {
+ LOG.trace("Skipping as s3 object is already in progress: {}",
fileName);
+ exchanges = new LinkedList<>();
+ } else {
+ try {
+ exchanges = createExchanges(getObject(bucketName,
fileName), fileName);
+ } catch (Exception e) {
+ // remove in progress as we failed
+ getEndpoint().getInProgressRepository().remove(fileName);
+ throw e;
Review Comment:
⚠️ **Resource leak:** `getObject()` returns a `ResponseInputStream` wrapping
an HTTP connection. If `createExchanges` throws (e.g. `IoUtils.toByteArray`
raises `IOException` → `RuntimeCamelException`), the stream is never closed
because it's passed inline with no captured reference.
Capture it first so it can be closed in the catch:
```suggestion
ResponseInputStream<GetObjectResponse> s3Object =
getObject(bucketName, fileName);
try {
exchanges = createExchanges(s3Object, fileName);
} catch (Exception e) {
IOHelper.close(s3Object);
// remove in progress as we failed
getEndpoint().getInProgressRepository().remove(fileName);
throw e;
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]