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

[RESTEASY-3135] Initial change for removing finalizers. #3102

Merged
merged 1 commit into from Jul 19, 2022

Conversation

jamezp
Copy link
Contributor

@jamezp jamezp commented May 20, 2022

https://issues.redhat.com/browse/RESTEASY-3135

This is not yet complete, but wanted to get some tests running.

@jamezp jamezp force-pushed the RESTEASY-3135 branch 2 times, most recently from c4f5121 to 0a74775 Compare May 27, 2022 23:49
@ronsigal
Copy link
Collaborator

@jamezp, can I just verify that I'm understanding "cleaning" correctly? It looks like

  1. the CleanupAction has a strong reference to a Message
  2. MultipartInputImpl has a strong reference to CleanupAction
  3. java.lang.ref.Cleaner holds a phantom reference to the CleanupAction

So, when MultipartInputImpl goes away, the Message becomes phantom reachable.

@jamezp
Copy link
Contributor Author

jamezp commented Jul 14, 2022

@jamezp, can I just verify that I'm understanding "cleaning" correctly? It looks like

  1. the CleanupAction has a strong reference to a Message
  2. MultipartInputImpl has a strong reference to CleanupAction
  3. java.lang.ref.Cleaner holds a phantom reference to the CleanupAction

So, when MultipartInputImpl goes away, the Message becomes phantom reachable.

@ronsigal That is how I'm hoping it works at least. The idea is that we don't keep MultipartInputImpl from being GC'd. I'm not 100% sure I got it right which is why I like this second set of eyes on it :)

@Override
public void close() {
cleanable.clean();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not clear about this. cleanable.clean() will set the AtomicBoolean closed to true. Then, if the CleanupAction gets called, closed.compareAndSet(false, true) returns false and client.close() doesn't happen. What am I missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When cleanable.clean() is invoked it's unregistered from the cleaner so it won't be cleaned again. https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/ref/Cleaner.Cleanable.html#clean()

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was stuck on

() -> closed.set(true)

instead of

ResourceCleaner.register(engine, new CleanupAction(closed, (CloseableHttpClient) client))

for some reason.

It makes sense now.

Looks good to me. What else needs to be done?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since you approved it, it just needs to be merged :)

@jamezp jamezp merged commit 27d79eb into resteasy:main Jul 19, 2022
@jamezp jamezp deleted the RESTEASY-3135 branch March 10, 2023 00:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants