Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix resource leak #8337

Merged
merged 2 commits into from Aug 20, 2019

Conversation

@asdf2014
Copy link
Member

commented Aug 19, 2019

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.

@leventov
Copy link
Member

left a comment

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

}
catch (InterruptedException e) {
log.error(e, "Queue appending interrupted");
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
finally {
if (channelStream != null) {
try {

This comment has been minimized.

Copy link
@leventov

leventov Aug 19, 2019

Member

This block is essentially CloseQuietly.close().

This comment has been minimized.

Copy link
@asdf2014

asdf2014 Aug 20, 2019

Author Member

Thanks, it is better.

@@ -116,6 +130,16 @@ public InputStream nextElement()
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
finally {
if (channelStream != null) {
try {

This comment has been minimized.

Copy link
@leventov

leventov Aug 19, 2019

Member

And here

This comment has been minimized.

Copy link
@asdf2014

asdf2014 Aug 20, 2019

Author Member

Changed.

@@ -214,7 +214,9 @@ public TimelineMetric druidEventToTimelineMetric(ServiceMetricEvent serviceMetri
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");

This comment has been minimized.

Copy link
@leventov

leventov Aug 19, 2019

Member

Simpler

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

This comment has been minimized.

Copy link
@asdf2014

asdf2014 Aug 20, 2019

Author Member

Thanks a lot 👍

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

This comment has been minimized.

Copy link
@leventov

leventov Aug 19, 2019

Member

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).

This comment has been minimized.

Copy link
@asdf2014

asdf2014 Aug 20, 2019

Author Member

Done.

@asdf2014

This comment has been minimized.

Copy link
Member Author

commented Aug 20, 2019

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 referenced this pull request Aug 20, 2019
1 of 8 tasks complete
@Fokko
Fokko approved these changes Aug 20, 2019

@leventov leventov merged commit 781873b into apache:master Aug 20, 2019

2 checks passed

Inspections: pull requests (Druid) TeamCity build finished
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@asdf2014 asdf2014 deleted the asdf2014:fix_resource_leak branch Aug 20, 2019

gianm added a commit to implydata/druid that referenced this pull request Aug 20, 2019
Fix resource leak (apache#8337)
* Fix resource leak

* Patch comments
gianm added a commit that referenced this pull request Aug 21, 2019
Docusaurus build framework + ingestion doc refresh. (#8311)
* 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
4 participants
You can’t perform that action at this time.