-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
statistics: release session met error to avoid possible leak #59522
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/hold |
/unhold |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #59522 +/- ##
================================================
+ Coverage 73.0108% 74.8468% +1.8359%
================================================
Files 1693 1739 +46
Lines 468044 476199 +8155
================================================
+ Hits 341723 356420 +14697
+ Misses 105314 97299 -8015
- Partials 21007 22480 +1473
Flags with carried forward coverage won't be shown. Click here to find out more.
|
@@ -85,6 +86,8 @@ func CallWithSCtx(pool util.SessionPool, f func(sctx sessionctx.Context) error, | |||
defer func() { | |||
if err == nil { // only recycle when no error | |||
pool.Put(se) | |||
} else { | |||
infosync.DeleteInternalSession(se) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to put the session in the pool after cleaning up the dirty state..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but how to clean it(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that if we return the session back to pool, the pool should be able to call DeleteInternalSession
Lines 1332 to 1346 in f6bf8e8
sysSessionPool: util.NewSessionPool( | |
capacity, factory, | |
func(r pools.Resource) { | |
_, ok := r.(sessionctx.Context) | |
intest.Assert(ok) | |
infosync.StoreInternalSession(r) | |
}, | |
func(r pools.Resource) { | |
sctx, ok := r.(sessionctx.Context) | |
intest.Assert(ok) | |
intest.AssertFunc(func() bool { | |
txn, _ := sctx.Txn(false) | |
return txn == nil || !txn.Valid() | |
}) | |
infosync.DeleteInternalSession(r) |
Can you reproduce this problem in our environment first? So we can use goref or other ways to know why the reference is kept
It is challenging to determine whether an error stems from the business logic or from the internal session. This complicates error handling when issues arise. As a result, we decided not to return the session to the pool, but this decision has led to memory leak problems. If we continue failing and create numerous sessions without properly releasing them, it exacerbates the issue. I propose that we introduce a new API for the session pool that allows the caller to destroy a session instead of directly returning it. |
This is not related to check the source of error? Line 88 of |
If we do not check the source of the error, we cannot put it back in the pool directly. This is also why we call |
closed since a better one is implemented |
What problem does this PR solve?
Issue Number: ref #54022 close #59524
Problem Summary:
We should release the session pool after abandoning it.
What changed and how does it work?
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.