Skip to content

Conversation

@niumy0701
Copy link

@niumy0701 niumy0701 commented Nov 25, 2025

Please refer to the details of main issue #14877
fix #17723

Purpose of the pull request

Brief change log

Verify this pull request

This pull request is code cleanup without any test coverage.

(or)

This pull request is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(or)

Pull Request Notice

Pull Request Notice

If your pull request contains incompatible change, you should also add it to docs/docs/en/guide/upgrade/incompatible.md

Copy link
Member

@SbloodyS SbloodyS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as #17719 (review)

@niumy0701 niumy0701 changed the title [DSIP-23][TaskPlugin] DmsTask resource leak repair [Improvement-17723][TaskPlugin] DmsTask resource leak repair Nov 25, 2025
@niumy0701 niumy0701 requested a review from SbloodyS November 25, 2025 07:59
@niumy0701 niumy0701 changed the title [Improvement-17723][TaskPlugin] DmsTask resource leak repair [Improvement-17723][TaskPlugin] DmsTask resource leak repair Nov 25, 2025
@niumy0701
Copy link
Author

Same as #17719 (review)

done
sub issue is #17723

@SbloodyS SbloodyS requested a review from Copilot November 26, 2025 02:00
Copilot finished reviewing on behalf of SbloodyS November 26, 2025 02:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request addresses resource leaks in the DMS task plugin by adding proper resource cleanup for AWS DMS clients and fixing a FileInputStream resource leak. However, the implementation introduces a critical bug in the checkFinishedReplicationTask() method where the client is shut down before it's fully used.

Key changes:

  • Added client.shutdown() calls to three methods (checkFinishedReplicationTask, stopReplicationTask, deleteReplicationTask) to prevent AWS client resource leaks
  • Fixed FileInputStream resource leak in replaceFileParameters using try-with-resources pattern
  • Added comprehensive test coverage for the replaceFileParameters method

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
DmsHook.java Added client shutdown calls to cleanup AWS DMS client resources; fixed FileInputStream leak with try-with-resources
DmsHookTest.java Added four new test cases for replaceFileParameters method covering null input, normal strings, existing files, and non-existent files

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Copy link
Member

@ruanwenjun ruanwenjun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add close method in DmsHook and close the hook in upper layer, if there throw any exception, still exist resource leak

@sonarqubecloud
Copy link

@niumy0701 niumy0701 requested a review from ruanwenjun November 29, 2025 07:56
@niumy0701
Copy link
Author

You need to add close method in DmsHook and close the hook in upper layer, if there throw any exception, still exist resource leak

thanks , It has been modified and can be reviewed again

try {
return IOUtils.toString(new FileInputStream(filePath), StandardCharsets.UTF_8);
try (FileInputStream fis = new FileInputStream(filePath)) {
return IOUtils.toString(fis, StandardCharsets.UTF_8);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Files.readString is better?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we minimize the changes and close the resources first, and then optimize them later

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just do it all at once? This is not a big change,

Comment on lines +144 to +156
try {
StopReplicationTaskRequest request = new StopReplicationTaskRequest()
.withReplicationTaskArn(replicationTaskArn);
client.stopReplicationTask(request);
awaitReplicationTaskStatus(STATUS.STOPPED);
} catch (Exception e) {
log.error("stopReplicationTask error: ", e);
} finally {
if (client != null) {
// shutdown client
client.shutdown();
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it need to close resources when canceling tasks, right

Copy link
Member

@ruanwenjun ruanwenjun Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to close resource when canceling, it will be close at handle lifecycle, have you test this? Please at least test in real environment when submit a PR.

@niumy0701 niumy0701 requested a review from ruanwenjun December 5, 2025 03:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement][TaskPlugin] DmsTask resource leak issue

3 participants