Fix multiple issues in SessionPool and PooledTableSession#153
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to improve robustness of SessionPool / TableSessionPool behavior (especially around error/close paths) and adds supporting e2e coverage, along with regenerated/extended Thrift types in common.
Changes:
- Add closed-state handling to
PooledTableSessionoperations and make connection-error cleanup idempotent. - Fix
SessionPoolsemaphore handling when session construction fails; add nil-checks aroundsession.trans. - Add an e2e test intended to exercise error scenarios in
TableSessionPool, and extend generated Thrift structs incommon/common.go.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| test/e2e/e2e_table_test.go | Adds a new e2e test for error/close behavior in TableSessionPool. |
| client/tablesessionpool.go | Adds ErrTableSessionClosed and hardens pooled session lifecycle on errors/close. |
| client/sessionpool.go | Adjusts semaphore release on construct failures and adds transport nil-checks. |
| common/common.go | Adds new Thrift-generated structs related to external services (plus minor regeneration diffs). |
Comments suppressed due to low confidence (2)
client/sessionpool.go:175
PutBackcan panic when sending onspool.ch(e.g., if the pool is concurrently closed). In that case the deferred recover runs, but<-spool.semis skipped because the function returns immediately after recover, leaking a semaphore token. Make semaphore release unconditional via a defer (and avoid doing it after the potentially panicking send).
defer func() {
if r := recover(); r != nil {
session.Close()
}
}()
if session.trans != nil && session.trans.IsOpen() {
spool.ch <- session
}
<-spool.sem
}
client/sessionpool.go:190
- Similarly to
PutBack, ifsession.Close()panics insidedropSession, the deferred recover prevents the panic from crashing but the code after the panic (including<-spool.sem) will not run, leaking a semaphore token. Release the semaphore in a defer so it happens even ifsession.Close()panics.
func (spool *SessionPool) dropSession(session Session) {
defer func() {
if e := recover(); e != nil {
if session.trans != nil && session.trans.IsOpen() {
session.Close()
}
}
}()
err := session.Close()
if err != nil {
log.Println("Failed to close session ", session)
}
<-spool.sem
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
HTHou
approved these changes
Feb 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.