Skip to content

Fix resource leak#8337

Merged
leventov merged 2 commits intoapache:masterfrom
asdf2014:fix_resource_leak
Aug 20, 2019
Merged

Fix resource leak#8337
leventov merged 2 commits intoapache:masterfrom
asdf2014:fix_resource_leak

Conversation

@asdf2014
Copy link
Copy Markdown
Member

Description

Fix resource leak


This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths.
  • added integration tests.
  • been tested in a test Druid cluster.

Copy link
Copy Markdown
Member

@leventov leventov left a comment

Choose a reason for hiding this comment

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

Great, thanks! How did you find all these leaks?

}
finally {
if (channelStream != null) {
try {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This block is essentially CloseQuietly.close().

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks, it is better.

}
finally {
if (channelStream != null) {
try {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Changed.

@@ -214,7 +214,9 @@ private ImmutableSortedMap<String, ImmutableList<String>> readMap(final String m
actualPath = this.getClass().getClassLoader().getResource("defaultWhiteListMap.json").getFile();
LOGGER.info("using default whiteList map located at [%s]", actualPath);
InputStream byteContent = this.getClass().getClassLoader().getResourceAsStream("defaultWhiteListMap.json");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Simpler

defaultWhiteListMapUrl = this.getClass().getClassLoader().getResource("defaultWhiteListMap.json");
actualPath = defaultWhiteListMapUrl.getFile();
LOGGER.info(...);
fileContent = Resources.toString(defaultWhiteListMapUrl, StandardCharsets.UTF_8);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks a lot 👍

new FileInputStream(trustStorePath),
trustStorePasswordProvider == null ? null : trustStorePasswordProvider.getPassword().toCharArray()
);
try (final FileInputStream trustStoreFileStream = new FileInputStream(trustStorePath)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While at this PR, please replace usages of FileInputStream/FileOutputStream in the places that you have touched with Files.newInputStream/Files.newOutputStream when possible. See this comment: #6677 (comment).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

@asdf2014
Copy link
Copy Markdown
Member Author

Great, thanks! How did you find all these leaks?

@leventov Thanks for your comments. The way to discover all resource leaks is the LGTM.

Before #8331

After #8331

Come on, let's get to A+ as soon as possible. I think it's time to add the LGTM shield to the README document. 💪

@asdf2014 asdf2014 mentioned this pull request Aug 20, 2019
8 tasks
@leventov leventov merged commit 781873b into apache:master Aug 20, 2019
@asdf2014 asdf2014 deleted the fix_resource_leak branch August 20, 2019 10:39
gianm pushed a commit to implydata/druid-public that referenced this pull request Aug 20, 2019
* Fix resource leak

* Patch comments
gianm added a commit that referenced this pull request Aug 21, 2019
* Docusaurus build framework + ingestion doc refresh.

* stick to npm instead of yarn

* fix typos

* restore some _bin

* Adjustments.

* detect and fix redirect anchors

* update anchor lint

* Web-console: remove specific column filters (#8343)

* add clear filter

* update tool kit

* remove usless check

* auto run

* add %

* Fix resource leak (#8337)

* Fix resource leak

* Patch comments

* Enable Spotbugs NP_NONNULL_RETURN_VIOLATION (#8234)

* Fixes from PR review.

* Fix more anchors.

* Preamble nix.

* Fix more anchors, headers

* clean up placeholder page

* add to website lint to travis config

* better broken link checking

* travis fix

* Fixed more broken links

* better redirects

* unfancy catch

* fix LGTM error

* link fixes

* fix md issues

* Addl fixes
@clintropolis clintropolis added this to the 0.16.0 milestone Aug 23, 2019
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.

4 participants