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

Fixes for resource leaks #24616

Merged
merged 12 commits into from
Feb 21, 2024
Merged

Fixes for resource leaks #24616

merged 12 commits into from
Feb 21, 2024

Conversation

dmatej
Copy link
Contributor

@dmatej dmatej commented Oct 1, 2023

I have this branch here since November 2022, rebasing it from time to time. Perhaps it would be good to merge it.

Summary of Changes:

  • In general - replacing GlassFish custom implementations where are modern implementations in the JDK already available.
  • Using try-with
  • Safer ZipEntry management, new closeable WritableArchiveEntry
  • Revisited FileUtils
    • deleted unused methods
    • added USER_HOME file
    • new ensureWritableDir method; if the directory cannot be used or created, throws ISE
  • ProprietaryReader.readFrom closes the input OR sets that to a returned object
    • The behavior is not much consistent and I don't like it, but now it is documented and better controlled.
    • Implementations are final to limit risks.
  • Fix: MIMEMessage is closeable!
  • Fix: JsonParser doesn't close the input if it is a stream!
  • AsadminSecurityUtil.GF_CLIENT_DIR constant
    • by default subdir in user's home as it was before this commit
    • can be reset by GF_CLIENT_DIR environment property.
    • MUST be writeable, client should crash otherwise.
  • ArchivistUtils deleted - duplicit to FileUtils
  • Fixed JAR/ZIP file management, entries
    • Safer impl without resource leaks (I hope, there's yet one class with really wide scope and also some finalizers, should be revisited later again).
    • More logs - it is hard to find what is wrong when it just does something in the background.
    • I wanted to write some tests around DeploymentContext, but it has too many dependencies, so it is covered just by integration tests (persistence_all ie)

The build locally passed:

mvn clean install
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  21:19 min
[INFO] Finished at: 2024-02-20T19:05:05+01:00
[INFO] ------------------------------------------------------------------------

I have read my own code now, it took me around 90 minutes. This is not a final state, there is several FIXMEs documenting discovered potential leaks which were too complicated for my brain and also they would need yet more radical changes. However this PR should improve the reliability+speed of GF a bit.

@dmatej dmatej added bug Something isn't working code cleaning labels Oct 1, 2023
@dmatej dmatej added this to the 7.0.10 milestone Oct 1, 2023
@dmatej dmatej self-assigned this Oct 1, 2023
@dmatej
Copy link
Contributor Author

dmatej commented Oct 6, 2023

My past me sent a message :D

     * FIXME: Document and write test with large zip file to see if it wouldn't be better to use
     * BufferedInputStream and BufferedOutputStream.
     * FIXME: Usually used with JarFile and it's entry. Add API.

- Using try-with
- Safer ZipEntry management, new closeable WritableArchiveEntry
- Revisited FileUtils
  - deleted unused methods
  - added USER_HOME file
  - new ensureWritableDir method; if the directory cannot be used or created,
    throws ISE
- ProprietaryReader.readFrom closes the input OR sets that to a returned object
  - The behavior is not much consistent and I don't like it, but now it is
    documented and better controlled.
  - Implementations are final to limit risks.
- Fix: MIMEMessage is closeable!
- Fix: JsonParser doesn't close the input if it is a stream!
- AsadminSecurityUtil.GF_CLIENT_DIR constant
  - by default subdir in user's home as it was before this commit
  - can be reset by GF_CLIENT_DIR environment property.
  - MUST be writeable, client should crash otherwise.
- ArchivistUtils deleted - duplicit to FileUtils

Signed-off-by: David Matějček <[email protected]>
- Safer impl without resource leaks (I hope, there's yet one class with really
  wide scope and also some finalizers, should be revisited later again).
- More logs - it is hard to find what is wrong when it just does something
  in the background.
- I wanted to write some tests around DeploymentContext, but it has too many
  dependencies, so it is covered just by integration tests (persistence_all ie)

Signed-off-by: David Matějček <[email protected]>

# Conflicts:
#	appserver/tests/testcontainers/src/test/java/org/glassfish/main/test/tc/GlassFishContainer.java
Signed-off-by: David Matějček <[email protected]>
Signed-off-by: David Matějček <[email protected]>

# Conflicts:
#	appserver/tests/testcontainers/pom.xml
#	appserver/tests/testcontainers/src/test/java/org/glassfish/main/test/tc/DomainRestartITest.java
#	appserver/tests/testcontainers/src/test/java/org/glassfish/main/test/tc/GlassFishContainer.java
Signed-off-by: David Matějček <[email protected]>

# Conflicts:
#	appserver/tests/testcontainers/pom.xml
#	appserver/tests/testcontainers/src/test/java/org/glassfish/main/test/tc/GlassFishContainer.java
Signed-off-by: David Matějček <[email protected]>
- it has to be refactored or rewritten to a more robust state

Signed-off-by: David Matějček <[email protected]>
Signed-off-by: David Matějček <[email protected]>

# Conflicts:
#	appserver/jms/jms-core/src/main/java/com/sun/enterprise/connectors/jms/system/JmsProviderLifecycle.java
Signed-off-by: David Matějček <[email protected]>
@dmatej dmatej marked this pull request as ready for review February 20, 2024 19:54
Copy link
Contributor

@arjantijms arjantijms left a comment

Choose a reason for hiding this comment

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

LGTM. TBH, didn't read each and every line.

@arjantijms arjantijms merged commit 352fc91 into eclipse-ee4j:master Feb 21, 2024
2 checks passed
@dmatej dmatej deleted the resource-leaks branch February 21, 2024 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working code cleaning
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants