Fix server hang on shared address

This commit is contained in:
tidwall 2022-09-12 16:38:45 -07:00
parent cbfb271541
commit 023433a963
2 changed files with 11 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import (
"io" "io"
"net" "net"
"sync" "sync"
"time"
"github.com/tidwall/redcon" "github.com/tidwall/redcon"
"github.com/tidwall/tile38/internal/log" "github.com/tidwall/tile38/internal/log"
@ -21,6 +22,13 @@ type liveBuffer struct {
} }
func (s *Server) processLives() { func (s *Server) processLives() {
defer s.lwait.Done()
go func() {
for {
s.lcond.Broadcast()
time.Sleep(time.Second / 4)
}
}()
s.lcond.L.Lock() s.lcond.L.Lock()
defer s.lcond.L.Unlock() defer s.lcond.L.Unlock()
for { for {

View File

@ -113,6 +113,7 @@ type Server struct {
lstack []*commandDetails lstack []*commandDetails
lives map[*liveBuffer]bool lives map[*liveBuffer]bool
lcond *sync.Cond lcond *sync.Cond
lwait sync.WaitGroup
fcup bool // follow caught up fcup bool // follow caught up
fcuponce bool // follow caught up once fcuponce bool // follow caught up once
shrinking bool // aof shrinking flag shrinking bool // aof shrinking flag
@ -312,6 +313,7 @@ func Serve(opts Options) error {
}() }()
} }
s.lwait.Add(1)
go s.processLives() go s.processLives()
go s.watchOutOfMemory() go s.watchOutOfMemory()
go s.watchLuaStatePool() go s.watchLuaStatePool()
@ -322,11 +324,7 @@ func Serve(opts Options) error {
// Stop background routines // Stop background routines
s.followc.add(1) // this will force any follow communication to die s.followc.add(1) // this will force any follow communication to die
s.stopServer.set(true) s.stopServer.set(true)
s.lwait.Wait()
// notify the live geofence connections that we are stopping.
s.lcond.L.Lock()
s.lcond.Wait()
s.lcond.L.Lock()
}() }()
// Server is now loaded and ready. Wait for network error messages. // Server is now loaded and ready. Wait for network error messages.