[bisq-network/bisq] Fix potential resource leak in AvoidStandbyModeService (#3909)

Steven Barclay notifications at github.com
Sun Jan 19 22:39:38 UTC 2020

- make yourself familiar with the CONTRIBUTING.md if you have not already (https://github.com/bisq-network/bisq/blob/master/CONTRIBUTING.md)
- make sure you follow our [coding style guidelines][https://github.com/bisq-network/style/issues)
- pick a descriptive title
- provide some meaningful PR description below
- create the PR
- in case you receive a "Change request" and/or a NACK, please react within 30 days. If not, we will close your PR and it can not be up for compensation.
- After addressing the change request, __please re-request a review!__ Otherwise we might miss your PR as we tend to only look at pull requests tagged with a "review required".

Replace tail recursion of the `AvoidStandbyModeService.play` method with an ordinary loop, to prevent a new open JAR resource InputStream + sound file OutputStream (which were created every 4 minute playback) from accumulating on the stack, closing them inside the loop instead. (This also prevents eventual stack overflow.)

Also tidy up `FileUtil.resourceToFile` and put the JAR URL InputStream in a try-with-resources block, to ensure that it doesn't leak either.


Running _lsof_ does reveal an accumulation of file handles without this fix, although not as many as one would expect from a new stream being opened every 4 minutes, suggesting that they were being closed in a finaliser:

![Screenshot from 2020-01-17 00-14-05](https://user-images.githubusercontent.com/54855381/72689639-5b42b980-3b0b-11ea-93af-2837e26594e3.png)

Also, JProfiler revealed an accumulation of `ZipInputStream` objects from loading the _.aiff_ JAR resource.
You can view, comment on, or merge this pull request online at:


-- Commit Summary --

  * Fix potential resource leak in AvoidStandbyModeService

-- File Changes --

    M common/src/main/java/bisq/common/storage/FileUtil.java (19)
    M core/src/main/java/bisq/core/app/AvoidStandbyModeService.java (74)

-- Patch Links --


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bisq.network/pipermail/bisq-github/attachments/20200119/e9b6ae60/attachment.html>

More information about the bisq-github mailing list