Skip to content

Add finalizers to ensure that repos are closed and blobreaders are closed (#19495) #19496

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

Merged
merged 9 commits into from
May 2, 2022

Conversation

zeripath
Copy link
Contributor

Backport #19495

It may be prudent to add runtime finalizers to the git.Repository and
git.blobReader objects to absolutely ensure that these are both properly
cancelled, cleaned and closed out.

This commit is a backport of an extract from #19448

Signed-off-by: Andrew Thornton [email protected]

…osed

It may be prudent to add runtime finalizers to the git.Repository and
git.blobReader objects to absolutely ensure that these are both properly
cancelled, cleaned and closed out.

This commit is a backport of an extract from go-gitea#19448

Signed-off-by: Andrew Thornton <[email protected]>
@zeripath zeripath added this to the 1.16.7 milestone Apr 25, 2022
@GiteaBot GiteaBot added the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Apr 25, 2022
Copy link
Contributor

@Gusted Gusted left a comment

Choose a reason for hiding this comment

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

In the Close function we want to set the the Finalizer of that object to nil.

Signed-off-by: Andrew Thornton <[email protected]>
@lunny
Copy link
Member

lunny commented Apr 26, 2022

I don't think it's a good idea.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Apr 26, 2022
@zeripath
Copy link
Contributor Author

In the Close function we want to set the the Finalizer of that object to nil.

Not necessarily. It's probably worth still rerunning the Close() again at time of GC().

@wxiaoguang
Copy link
Contributor

For 1.16, it might work and might resolve some resource leaking problems.

For 1.17, I am a little conservative about it. The reason is that GC time can not be controlled (well, should not be controlled), and sometimes the leaked resource may be still referenced by other variables while the resource itself should be closed. So I think it's safer and proper to fix these leaked resources if there is a chance. The runtime finalizers might help developers to find these leaked resources.

@zeripath
Copy link
Contributor Author

Please note, I have no information to suggest that we have any leaks, nor that we should consider that relying on finalizers is a good idea.

However, if we do have leaks - it is infinitely better for a finalizer to take care of them than to have a leak there.

Signed-off-by: Andrew Thornton <[email protected]>
@zeripath zeripath changed the title Add finalizers to ensure that repos are closed and blobreaders are closed Add finalizers to ensure that repos are closed and blobreaders are closed (#19495) Apr 26, 2022
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Apr 27, 2022

Please note, I have no information to suggest that we have any leaks, nor that we should consider that relying on finalizers is a good idea.

If no leak, why the finalizers are needed? Close a already closed object?

However, if we do have leaks - it is infinitely better for a finalizer to take care of them than to have a leak there.

I also agree that finalizers can help to prevent leaking. I mean if there are some leaks, we need logs to tell developers that there is something incorrect.


I saw more details in #19495 👍

@6543
Copy link
Member

6543 commented May 1, 2022

hop or top - should we move or merge?!

@6543 6543 modified the milestones: 1.16.7, 1.16.8 May 2, 2022
@wxiaoguang
Copy link
Contributor

Vote to merge

@Gusted
Copy link
Contributor

Gusted commented May 2, 2022

Agree to merge this. It doesn't any harm to merge and is a nice safety measurement.

@wxiaoguang wxiaoguang merged commit 88da506 into go-gitea:release/v1.16 May 2, 2022
@zeripath zeripath deleted the backport-set-finalizer branch May 6, 2022 19:47
@ashimokawa
Copy link
Contributor

This PR introduced a memory leak on codeberg.org leading to about 25GB of leaked memory in 2 days. We had to revert it.

I think the real cause should be fixed before the next release.

lunny added a commit that referenced this pull request May 9, 2022
6543 pushed a commit that referenced this pull request May 9, 2022
…s are closed (#19495) (#19496)" (#19659)

This reverts commit 88da506.

because it caused a memleak
@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants