Skip to content

Commit e7ab34e

Browse files
THRIFT-5897: Use Read Lock for Listener in TServerSocket.Accept()
Problem: Accept() previously used two separate lock acquisitions: RLock() to read interrupted field Lock() (write lock) to read listener field Write lock was unnecessary since listener is only being read, not modified Write locks block all other goroutines (both readers and writers) Solution: Consolidate both field reads under a single RLock()/RUnlock() pair Both interrupted and listener are read-only operations, so read lock is sufficient
1 parent 3b21bc9 commit e7ab34e

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

lib/go/thrift/server_socket.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,13 @@ func (p *TServerSocket) Listen() error {
6969
func (p *TServerSocket) Accept() (TTransport, error) {
7070
p.mu.RLock()
7171
interrupted := p.interrupted
72+
listener := p.listener
7273
p.mu.RUnlock()
7374

7475
if interrupted {
7576
return nil, errTransportInterrupted
7677
}
7778

78-
p.mu.Lock()
79-
listener := p.listener
80-
p.mu.Unlock()
8179
if listener == nil {
8280
return nil, NewTTransportException(NOT_OPEN, "No underlying server socket")
8381
}

0 commit comments

Comments
 (0)