Skip to content

Commit 550660b

Browse files
committed
Fix deadlock in topology update close logic
1 parent 0c9b061 commit 550660b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

core/topology/server.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,12 @@ func (s *Server) update() {
247247
checkNow := s.checkNow
248248
done := s.done
249249

250+
var doneOnce bool
250251
defer func() {
251252
if r := recover(); r != nil {
253+
if doneOnce {
254+
return
255+
}
252256
// We keep this goroutine alive attempting to read from the done channel.
253257
<-done
254258
}
@@ -261,13 +265,17 @@ func (s *Server) update() {
261265
s.updateDescription(desc, true)
262266

263267
closeServer := func() {
268+
doneOnce = true
264269
s.subLock.Lock()
265270
for id, c := range s.subscribers {
266271
close(c)
267272
delete(s.subscribers, id)
268273
}
269274
s.subscriptionsClosed = true
270275
s.subLock.Unlock()
276+
if conn == nil {
277+
return
278+
}
271279
conn.Close()
272280
}
273281
for {

0 commit comments

Comments
 (0)