Skip to content

Commit

Permalink
Fix server hang on shared address
Browse files Browse the repository at this point in the history
  • Loading branch information
tidwall committed Sep 12, 2022
1 parent cbfb271 commit 023433a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 8 additions & 0 deletions internal/server/live.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"net"
"sync"
"time"

"github.com/tidwall/redcon"
"github.com/tidwall/tile38/internal/log"
Expand All @@ -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 {
Expand Down
8 changes: 3 additions & 5 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -312,6 +313,7 @@ func Serve(opts Options) error {
}()
}

s.lwait.Add(1)
go s.processLives()
go s.watchOutOfMemory()
go s.watchLuaStatePool()
Expand All @@ -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.
Expand Down

0 comments on commit 023433a

Please sign in to comment.