THRIFT-4659: Fix race when closing server socket (#1645)
Client: go
diff --git a/lib/go/thrift/server_socket.go b/lib/go/thrift/server_socket.go
index 80313c4..7dd24ae 100644
--- a/lib/go/thrift/server_socket.go
+++ b/lib/go/thrift/server_socket.go
@@ -75,7 +75,9 @@
return nil, errTransportInterrupted
}
+ p.mu.Lock()
listener := p.listener
+ p.mu.Unlock()
if listener == nil {
return nil, NewTTransportException(NOT_OPEN, "No underlying server socket")
}
@@ -115,19 +117,20 @@
}
func (p *TServerSocket) Close() error {
- defer func() {
- p.listener = nil
- }()
+ var err error
+ p.mu.Lock()
if p.IsListening() {
- return p.listener.Close()
+ err = p.listener.Close()
+ p.listener = nil
}
- return nil
+ p.mu.Unlock()
+ return err
}
func (p *TServerSocket) Interrupt() error {
p.mu.Lock()
- defer p.mu.Unlock()
p.interrupted = true
+ p.mu.Unlock()
p.Close()
return nil