Commit 72f29a8d authored by zhiqiangxu's avatar zhiqiangxu Committed by GitHub

fix `AsyncGossiper` hangup (#10654)

* fix AsyncGossiper hangup

* Use atomic operation when starting.

---------
Co-authored-by: default avatarAdrian Sutton <adrian@oplabs.co>
parent 926ba712
......@@ -90,6 +90,11 @@ func (p *SimpleAsyncGossiper) Clear() {
// Stop is a synchronous function to stop the async routine
// it blocks until the async routine accepts the signal
func (p *SimpleAsyncGossiper) Stop() {
// if the gossiping isn't running, nothing to do
if !p.running.Load() {
return
}
p.stop <- struct{}{}
}
......@@ -97,10 +102,9 @@ func (p *SimpleAsyncGossiper) Stop() {
// each behavior of the loop is handled by a select case on a channel, plus an internal handler function call
func (p *SimpleAsyncGossiper) Start() {
// if the gossiping is already running, return
if p.running.Load() {
if !p.running.CompareAndSwap(false, true) {
return
}
p.running.Store(true)
// else, start the handling loop
go func() {
defer p.running.Store(false)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment