Skip to content

Fix multiple issues in SessionPool and PooledTableSession#153

Merged
HTHou merged 4 commits intomainfrom
fixBugs-0226
Feb 26, 2026
Merged

Fix multiple issues in SessionPool and PooledTableSession#153
HTHou merged 4 commits intomainfrom
fixBugs-0226

Conversation

@shuwenwei
Copy link
Member

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 PooledTableSession operations and make connection-error cleanup idempotent.
  • Fix SessionPool semaphore handling when session construction fails; add nil-checks around session.trans.
  • Add an e2e test intended to exercise error scenarios in TableSessionPool, and extend generated Thrift structs in common/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

  • PutBack can panic when sending on spool.ch (e.g., if the pool is concurrently closed). In that case the deferred recover runs, but <-spool.sem is 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, if session.Close() panics inside dropSession, 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 if session.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 HTHou merged commit f00cf99 into main Feb 26, 2026
6 checks passed
@HTHou HTHou deleted the fixBugs-0226 branch February 26, 2026 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants