THRIFT-3855 In the go simple server, if Stop() is called multiple times it hangs
Client: Go
Patch: ZhiyuYin <yinzhiyu@xiaomi.com>
This closes #1028
diff --git a/lib/go/thrift/simple_server.go b/lib/go/thrift/simple_server.go
index a54d804..6b3811e 100644
--- a/lib/go/thrift/simple_server.go
+++ b/lib/go/thrift/simple_server.go
@@ -22,11 +22,13 @@
import (
"log"
"runtime/debug"
+ "sync/atomic"
)
// Simple, non-concurrent server for testing.
type TSimpleServer struct {
quit chan struct{}
+ stopped int64
processorFactory TProcessorFactory
serverTransport TServerTransport
@@ -149,8 +151,10 @@
}
func (p *TSimpleServer) Stop() error {
- p.quit <- struct{}{}
- p.serverTransport.Interrupt()
+ if atomic.CompareAndSwapInt64(&p.stopped, 0, 1) {
+ p.quit <- struct{}{}
+ p.serverTransport.Interrupt()
+ }
return nil
}