-
Notifications
You must be signed in to change notification settings - Fork 13
Revert connpool fix connection leak #207
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
base: release-21.0-github
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -435,13 +435,9 @@ func (pool *ConnPool[C]) pop(stack *connStack[C]) *Pooled[C] { | |||||||||||||||||||||||||
| // to expire this connection (even if it's still visible to them), so it's | ||||||||||||||||||||||||||
| // safe to return it | ||||||||||||||||||||||||||
| for conn, ok := stack.Pop(); ok; conn, ok = stack.Pop() { | ||||||||||||||||||||||||||
| if !conn.timeUsed.borrow() { | ||||||||||||||||||||||||||
| // Ignore the connection that couldn't be borrowed; | ||||||||||||||||||||||||||
| // it's being closed by the idle worker and replaced by a new connection. | ||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||
| if conn.timeUsed.borrow() { | ||||||||||||||||||||||||||
| return conn | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return conn | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
@@ -746,23 +742,11 @@ func (pool *ConnPool[C]) closeIdleResources(now time.Time) { | |||||||||||||||||||||||||
| for conn := s.Peek(); conn != nil; conn = conn.next.Load() { | ||||||||||||||||||||||||||
| if conn.timeUsed.expired(mono, timeout) { | ||||||||||||||||||||||||||
| pool.Metrics.idleClosed.Add(1) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| conn.Close() | ||||||||||||||||||||||||||
| pool.closedConn() | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Using context.Background() is fine since MySQL connection already enforces | ||||||||||||||||||||||||||
| // a connect timeout via the `db_connect_timeout_ms` config param. | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| // a connect timeout via the `db_connect_timeout_ms` config param. | |
| // a connect timeout via the `db_connect_timeout_ms` config param. | |
| // NOTE: We intentionally call connReopen() here instead of using the | |
| // getNew() + tryReturnConn() pattern. An earlier change switched this | |
| // logic to allocate a new connection and return the old one to the pool, | |
| // but that approach was reverted in v21 due to a version-specific memory | |
| // leak in the connection pooling layer. Reopening the existing connection | |
| // object avoids that leak at the cost of reusing connection structs | |
| // more aggressively and potentially holding onto them longer. If this | |
| // behavior is revisited in the future, carefully reassess memory usage, | |
| // pool accounting, and leak risks before switching back to getNew() + | |
| // tryReturnConn(). |
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.
The reverted logic may reintroduce the original connection leak issue. After reverting, when
borrow()fails (connection is expired/busy), the loop continues to the next connection but doesn't handle the failed connection, leaving it in the stack. Consider documenting why this approach is acceptable in v21 and what trade-offs are being made by accepting potential leaked connections versus the memory leak caused by the fix.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.
Hggh