Details
-
Bug
-
Resolution: Fixed
-
Major
-
11.10.5
-
Unknown
-
N/A
-
N/A
-
Description
We have many places in platform where we use an InputStream but forget to close it. This can lead to resource leaks (e.g. unreleased file descriptors) and other problems over the lifetime of a running XWiki instance.
After going through the output of a simple grep (that excludes test):
grep "getResourceAsStream" . -R --exclude-dir=target* --exclude-dir=test
...and filtering out the valid usages, I ended up with this relatively complete list of problems in xwiki-platform that need to be addressed and the used InputStreams need to be closed (generally by using try-with-catch in most cases):
- https://github.com/xwiki/xwiki-platform/blob/bd6021759c09bf8952949e4efd4a5141b739aa08/xwiki-platform-core/xwiki-platform-skin/xwiki-platform-skin-skinx/src/main/java/com/xpn/xwiki/web/sx/SxResourceSource.java#L60
- ? https://github.com/xwiki/xwiki-platform/blob/bd6021759c09bf8952949e4efd4a5141b739aa08/xwiki-platform-tools/xwiki-platform-tool-standards-validator/src/main/java/org/xwiki/validator/framework/XMLResourcesEntityResolver.java#L53
- https://github.com/xwiki/xwiki-platform/blob/bd6021759c09bf8952949e4efd4a5141b739aa08/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/pdf/impl/FileSystemURLFactory.java#L195
- https://github.com/xwiki/xwiki-platform/blob/bd6021759c09bf8952949e4efd4a5141b739aa08/xwiki-platform-core/xwiki-platform-icon/xwiki-platform-icon-default/src/main/java/org/xwiki/icon/internal/DefaultIconSetManager.java#L129
- https://github.com/xwiki/xwiki-platform/blob/bd6021759c09bf8952949e4efd4a5141b739aa08/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-oldcore/src/main/java/com/xpn/xwiki/internal/web/XWikiConfigurationService.java#L89
- - the catch should close the inputStream if one of the paths managed to open it
- https://github.com/xwiki/xwiki-platform/blob/bd6021759c09bf8952949e4efd4a5141b739aa08/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/XWikiConfig.java#L64
- https://github.com/xwiki/xwiki-platform/blob/bd6021759c09bf8952949e4efd4a5141b739aa08/xwiki-platform-core/xwiki-platform-resource/xwiki-platform-resource-servlet/src/main/java/org/xwiki/resource/servlet/AbstractServletResourceReferenceHandler.java#L82
- https://github.com/xwiki/xwiki-platform/blob/bd6021759c09bf8952949e4efd4a5141b739aa08/xwiki-platform-core/xwiki-platform-resource/xwiki-platform-resource-default/src/main/java/org/xwiki/resource/internal/entity/DefaultEntityResourceActionLister.java#L97
- https://github.com/xwiki/xwiki-platform/blob/bd6021759c09bf8952949e4efd4a5141b739aa08/xwiki-platform-core/xwiki-platform-observation/xwiki-platform-observation-remote/src/main/java/org/xwiki/observation/remote/internal/jgroups/JGroupsNetworkAdapter.java#L215
- https://github.com/xwiki/xwiki-platform/blob/bd6021759c09bf8952949e4efd4a5141b739aa08/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/internal/XWikiCfgConfigurationSource.java#L104
- https://github.com/xwiki/xwiki-platform/blob/bd6021759c09bf8952949e4efd4a5141b739aa08/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/R35100XWIKI7564DataMigration.java#L115
- https://github.com/xwiki/xwiki-platform/blob/bd6021759c09bf8952949e4efd4a5141b739aa08/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/pdf/impl/PdfExportImpl.java#L279
- https://github.com/xwiki/xwiki-platform/blob/bd6021759c09bf8952949e4efd4a5141b739aa08/xwiki-platform-core/xwiki-platform-eventstream/xwiki-platform-eventstream-stores/xwiki-platform-eventstream-store-hibernate/src/main/java/org/xwiki/eventstream/store/internal/EventStreamStoreInitializer.java#L75
- - the same for the else branch
- https://github.com/xwiki/xwiki-platform/blob/bd6021759c09bf8952949e4efd4a5141b739aa08/xwiki-platform-core/xwiki-platform-office/xwiki-platform-office-importer/src/main/java/org/xwiki/officeimporter/internal/server/DefaultOfficeServer.java#L150
- https://github.com/xwiki/xwiki-platform/blob/bd6021759c09bf8952949e4efd4a5141b739aa08/xwiki-platform-core/xwiki-platform-index/xwiki-platform-index-tree/xwiki-platform-index-tree-api/src/main/java/org/xwiki/index/tree/internal/nestedpages/query/QueryRegistrationHandler.java#L73
I got the idea to check this after watching this relevant part of this video: https://www.youtube.com/watch?v=c755fFv1Rnk&t=45m10s (even more details on the problem and how the memory grew in that example in the previous minutes).