diff options
Diffstat (limited to 'lib/go/thrift/simple_server.go')
-rw-r--r-- | lib/go/thrift/simple_server.go | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/go/thrift/simple_server.go b/lib/go/thrift/simple_server.go index 31dfa1e6d..c5c14feed 100644 --- a/lib/go/thrift/simple_server.go +++ b/lib/go/thrift/simple_server.go @@ -54,7 +54,7 @@ var ServerStopTimeout = time.Duration(0) * This will work if golang user implements a conn-pool like thing in client side. */ type TSimpleServer struct { - closed int32 + closed atomic.Int32 wg sync.WaitGroup mu sync.Mutex stopChan chan struct{} @@ -186,7 +186,7 @@ func (p *TSimpleServer) innerAccept() (int32, error) { client, err := p.serverTransport.Accept() p.mu.Lock() defer p.mu.Unlock() - closed := atomic.LoadInt32(&p.closed) + closed := p.closed.Load() if closed != 0 { return closed, nil } @@ -246,10 +246,10 @@ func (p *TSimpleServer) Stop() error { p.mu.Lock() defer p.mu.Unlock() - if atomic.LoadInt32(&p.closed) != 0 { + if !p.closed.CompareAndSwap(0, 1) { + // Already closed return nil } - atomic.StoreInt32(&p.closed, 1) p.serverTransport.Interrupt() ctx, cancel := context.WithCancel(context.Background()) @@ -328,7 +328,7 @@ func (p *TSimpleServer) processRequests(client TTransport) (err error) { defer outputTransport.Close() } for { - if atomic.LoadInt32(&p.closed) != 0 { + if p.closed.Load() != 0 { return nil } |