From 023433a9632a68ceffcec3f5e7fc06a12fffdf56 Mon Sep 17 00:00:00 2001 From: tidwall Date: Mon, 12 Sep 2022 16:38:45 -0700 Subject: [PATCH] Fix server hang on shared address --- internal/server/live.go | 8 ++++++++ internal/server/server.go | 8 +++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/internal/server/live.go b/internal/server/live.go index 1f595327..eb66ec64 100644 --- a/internal/server/live.go +++ b/internal/server/live.go @@ -7,6 +7,7 @@ import ( "io" "net" "sync" + "time" "github.com/tidwall/redcon" "github.com/tidwall/tile38/internal/log" @@ -21,6 +22,13 @@ type liveBuffer struct { } func (s *Server) processLives() { + defer s.lwait.Done() + go func() { + for { + s.lcond.Broadcast() + time.Sleep(time.Second / 4) + } + }() s.lcond.L.Lock() defer s.lcond.L.Unlock() for { diff --git a/internal/server/server.go b/internal/server/server.go index 09023962..00306cb4 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -113,6 +113,7 @@ type Server struct { lstack []*commandDetails lives map[*liveBuffer]bool lcond *sync.Cond + lwait sync.WaitGroup fcup bool // follow caught up fcuponce bool // follow caught up once shrinking bool // aof shrinking flag @@ -312,6 +313,7 @@ func Serve(opts Options) error { }() } + s.lwait.Add(1) go s.processLives() go s.watchOutOfMemory() go s.watchLuaStatePool() @@ -322,11 +324,7 @@ func Serve(opts Options) error { // Stop background routines s.followc.add(1) // this will force any follow communication to die s.stopServer.set(true) - - // notify the live geofence connections that we are stopping. - s.lcond.L.Lock() - s.lcond.Wait() - s.lcond.L.Lock() + s.lwait.Wait() }() // Server is now loaded and ready. Wait for network error messages.