Skip to content

Commit 2620a12

Browse files
AtharvaChiplunkar12fishy
authored andcommitted
THRIFT-5896: Fix race condition in TServerSocket.Addr()
Client: go
1 parent d9a97c1 commit 2620a12

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/go/thrift/server_socket.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ import (
2626
)
2727

2828
type TServerSocket struct {
29-
listener net.Listener
3029
addr net.Addr
3130
clientTimeout time.Duration
3231

33-
// Protects the interrupted value to make it thread safe.
32+
// Protects the listener and interrupted fields to make them thread safe.
3433
mu sync.RWMutex
34+
listener net.Listener
3535
interrupted bool
3636
}
3737

@@ -110,7 +110,9 @@ func (p *TServerSocket) Open() error {
110110
}
111111

112112
func (p *TServerSocket) Addr() net.Addr {
113-
if p.listener != nil {
113+
p.mu.RLock()
114+
defer p.mu.RUnlock()
115+
if p.IsListening() {
114116
return p.listener.Addr()
115117
}
116118
return p.addr

0 commit comments

Comments
 (0)