Skip to content

Commit

Permalink
Fix possible write to closed chan error
Browse files Browse the repository at this point in the history
Wait for connection pool serveHandlers goroutine to finish
before resolving of the done chan.
  • Loading branch information
ghettovoice committed Jun 20, 2024
1 parent afc3f00 commit f0e1df9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions transport/connection_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ type connectionPool struct {
errs chan<- error
cancel <-chan struct{}

done chan struct{}
hmess chan sip.Message
herrs chan error
done chan struct{}
hmess chan sip.Message
herrs chan error
srvhDone chan struct{}

hwg sync.WaitGroup
mu sync.RWMutex
Expand All @@ -83,9 +84,10 @@ func NewConnectionPool(
errs: errs,
cancel: cancel,

done: make(chan struct{}),
hmess: make(chan sip.Message),
herrs: make(chan error),
done: make(chan struct{}),
hmess: make(chan sip.Message),
herrs: make(chan error),
srvhDone: make(chan struct{}),
}

pool.log = logger.
Expand Down Expand Up @@ -200,13 +202,16 @@ func (pool *connectionPool) dispose() {
close(pool.hmess)
close(pool.herrs)

<-pool.srvhDone
close(pool.done)
}

func (pool *connectionPool) serveHandlers() {
pool.Log().Debug("begin serve connection handlers")
defer pool.Log().Debug("stop serve connection handlers")

defer close(pool.srvhDone)

for {
logger := pool.Log()

Expand Down

0 comments on commit f0e1df9

Please sign in to comment.