opensearch-project / OpenSearch

🔎 Open source distributed and RESTful search engine.
https://opensearch.org/docs/latest/opensearch/index/
Apache License 2.0
8.89k stars 1.63k forks source link

Fix resource leak issues suggested by Amazon CodeGuru #816

Closed tlfeng closed 2 years ago

tlfeng commented 2 years ago

Description

Address a kind of issue suggested by Amazon CodeGuru Reviewer.

  1. Add try-with-resources block to automatically close the resources after using to avoid resource leak.

    • Close FileInputStream in SymbolicLinkPreservingTarIT, LicenseAnalyzer, SymbolicLinkPreservingUntarTransform and ConcurrentSeqNoVersioningIT classes
    • Close InputStream in VersionProperties and GeoFilterIT classes
    • Close one variable of InputStream in XContentHelper class
    • Close OutputStream in Json class
    • Close PrintStream and BytesStreamOutput in IndexShard class
  2. Add try-finally block to close the resources after using to avoid resource leak.

    • Close SocketChannel in ServerChannelContext class
  3. Add try-catch block to close the resources when exception occurs.

    • Close other InputStream in XContentHelper class when XContentFactory.xContentType throws an exception - Close SeekableByteChannel in FsBlobContainer class
  4. Close resources when assertion error occurs.

    • Close SocketChannel in ServerChannelContext class

Reference: The change in LicenseAnalyzer class is copied from #692

Issues Resolved

[List any issues this PR will resolve]

Check List

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. For more information on following Developer Certificate of Origin and signing off your commits, please check here.

opensearch-ci-bot commented 2 years ago

:white_check_mark:   DCO Check Passed cc6714587a6c98dde934a2e723607392d6fa3067

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Wrapper Validation success cc6714587a6c98dde934a2e723607392d6fa3067

opensearch-ci-bot commented 2 years ago

:x:   Gradle Precommit failure cc6714587a6c98dde934a2e723607392d6fa3067 Log 526

opensearch-ci-bot commented 2 years ago

:x:   DCO Check Failed de804d0634ddf14f9dbf055254eec27cfa255702 Run ./dev-tools/signoff-check.sh remotes/origin/main de804d0634ddf14f9dbf055254eec27cfa255702 to check locally Use git commit with -s to add 'Signed-of-by: {EMAIL}' on impacted commits

opensearch-ci-bot commented 2 years ago

:x:   Gradle Precommit failure 572cc3d233a2fa450ccf90a6f6c531155f1d3e2a Log 527

opensearch-ci-bot commented 2 years ago

:x:   Gradle Wrapper Validation failure 572cc3d233a2fa450ccf90a6f6c531155f1d3e2a

:alert: Gradle Wrapper integrity has been altered

opensearch-ci-bot commented 2 years ago

:white_check_mark:   DCO Check Passed 8c52959cbb816b8402eb04187259b05319752f9d

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Wrapper Validation success 8c52959cbb816b8402eb04187259b05319752f9d

opensearch-ci-bot commented 2 years ago

:x:   Gradle Precommit failure 8c52959cbb816b8402eb04187259b05319752f9d Log 528

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Wrapper Validation success 65dc3c7f9854f1753356f03aa52013df39dcf54f

opensearch-ci-bot commented 2 years ago

:white_check_mark:   DCO Check Passed 65dc3c7f9854f1753356f03aa52013df39dcf54f

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Precommit success 65dc3c7f9854f1753356f03aa52013df39dcf54f

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Wrapper Validation success 7eba7d327c34b2b8dae65aeb2bf8272b91ad6b8b

opensearch-ci-bot commented 2 years ago

:white_check_mark:   DCO Check Passed 7eba7d327c34b2b8dae65aeb2bf8272b91ad6b8b

opensearch-ci-bot commented 2 years ago

:white_check_mark:   DCO Check Passed 653f934ce9b6b7020aad12cc042a944002b33913

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Wrapper Validation success 653f934ce9b6b7020aad12cc042a944002b33913

opensearch-ci-bot commented 2 years ago

:x:   Gradle Precommit failure 7eba7d327c34b2b8dae65aeb2bf8272b91ad6b8b Log 531

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Precommit success 653f934ce9b6b7020aad12cc042a944002b33913

opensearch-ci-bot commented 2 years ago

:x:   DCO Check Failed 8f408a4fe6438eb3a082d4ac66d3a60c061e0077 Run ./dev-tools/signoff-check.sh remotes/origin/main 8f408a4fe6438eb3a082d4ac66d3a60c061e0077 to check locally Use git commit with -s to add 'Signed-of-by: {EMAIL}' on impacted commits

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Wrapper Validation success 4e6e9c42722854098162bdef5ba198557d9150ec

opensearch-ci-bot commented 2 years ago

:white_check_mark:   DCO Check Passed 4e6e9c42722854098162bdef5ba198557d9150ec

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Precommit success 4e6e9c42722854098162bdef5ba198557d9150ec

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Wrapper Validation success c96ab193cfe44149df2a4e4cf25181d30df5b5d1

opensearch-ci-bot commented 2 years ago

:white_check_mark:   DCO Check Passed c96ab193cfe44149df2a4e4cf25181d30df5b5d1

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Precommit success c96ab193cfe44149df2a4e4cf25181d30df5b5d1

opensearch-ci-bot commented 2 years ago

:x:   Gradle Precommit failure b00a009e7bff239fc6b32940f5dc7cc5d79f2184 Log 536

opensearch-ci-bot commented 2 years ago

:x:   Gradle Wrapper Validation failure b00a009e7bff239fc6b32940f5dc7cc5d79f2184

:alert: Gradle Wrapper integrity has been altered

opensearch-ci-bot commented 2 years ago

:white_check_mark:   DCO Check Passed e3f4b2f3aaa439ebd2e8c6be9ef88feffea93f32

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Wrapper Validation success e3f4b2f3aaa439ebd2e8c6be9ef88feffea93f32

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Precommit success e3f4b2f3aaa439ebd2e8c6be9ef88feffea93f32

opensearch-ci-bot commented 2 years ago

:white_check_mark:   DCO Check Passed 3f35bb79baad9f8949289f41655c49c03d4dbbf8

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Wrapper Validation success 3f35bb79baad9f8949289f41655c49c03d4dbbf8

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Precommit success 3f35bb79baad9f8949289f41655c49c03d4dbbf8

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Wrapper Validation success 76ad93493852c90c58378b687399f80fb9370609

opensearch-ci-bot commented 2 years ago

:white_check_mark:   DCO Check Passed 76ad93493852c90c58378b687399f80fb9370609

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Wrapper Validation success d3289c27529cc6f07bc5f558485942806f5c9777

opensearch-ci-bot commented 2 years ago

:white_check_mark:   DCO Check Passed d3289c27529cc6f07bc5f558485942806f5c9777

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Precommit success 76ad93493852c90c58378b687399f80fb9370609

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Precommit success d3289c27529cc6f07bc5f558485942806f5c9777

opensearch-ci-bot commented 2 years ago

:white_check_mark:   DCO Check Passed 2063fcf95ce4504101f22f73e1b68681dc76c9fa

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Wrapper Validation success 2063fcf95ce4504101f22f73e1b68681dc76c9fa

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Precommit success 2063fcf95ce4504101f22f73e1b68681dc76c9fa

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Wrapper Validation success a186576ba0b7a32321eec2c84b67788aaa796ab3

opensearch-ci-bot commented 2 years ago

:x:   Gradle Precommit failure a186576ba0b7a32321eec2c84b67788aaa796ab3 Log 550

opensearch-ci-bot commented 2 years ago

:x:   DCO Check Failed a186576ba0b7a32321eec2c84b67788aaa796ab3 Run ./dev-tools/signoff-check.sh remotes/origin/main a186576ba0b7a32321eec2c84b67788aaa796ab3 to check locally Use git commit with -s to add 'Signed-of-by: {EMAIL}' on impacted commits

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Wrapper Validation success 22f054aab988280be5fd9f685144c522c84bdd78

opensearch-ci-bot commented 2 years ago

:white_check_mark:   DCO Check Passed 22f054aab988280be5fd9f685144c522c84bdd78

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Precommit success 22f054aab988280be5fd9f685144c522c84bdd78

opensearch-ci-bot commented 2 years ago

:white_check_mark:   Gradle Wrapper Validation success aabf2053d94f789226e4d4c08e97c79ff61f4f74

opensearch-ci-bot commented 2 years ago

:white_check_mark:   DCO Check Passed aabf2053d94f789226e4d4c08e97c79ff61f4f74