Redis Router graceful stop (#116)
* prestop and hasparticipants in interface * add prestop function to existing routers * fakerouter prestop * update protocol version * read lock * redis router graceful stop * test fix * force stop
This commit is contained in:
@@ -41,5 +41,6 @@ type RoomManager interface {
|
||||
StartSession(ctx context.Context, roomName string, pi routing.ParticipantInit, requestSource routing.MessageSource, responseSink routing.MessageSink)
|
||||
CleanupRooms() error
|
||||
CloseIdleRooms()
|
||||
HasParticipants() bool
|
||||
Stop()
|
||||
}
|
||||
|
||||
@@ -202,6 +202,18 @@ func (r *LocalRoomManager) CloseIdleRooms() {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *LocalRoomManager) HasParticipants() bool {
|
||||
r.lock.RLock()
|
||||
defer r.lock.RUnlock()
|
||||
|
||||
for _, room := range r.rooms {
|
||||
if len(room.GetParticipants()) != 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *LocalRoomManager) Stop() {
|
||||
// disconnect all clients
|
||||
r.lock.RLock()
|
||||
|
||||
+15
-6
@@ -171,7 +171,7 @@ func (s *LivekitServer) Start() error {
|
||||
logger.Infow("starting LiveKit server", values...)
|
||||
if err := s.httpServer.Serve(ln); err != http.ErrServerClosed {
|
||||
logger.Errorw("could not start server", err)
|
||||
s.Stop()
|
||||
s.Stop(true)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -184,10 +184,6 @@ func (s *LivekitServer) Start() error {
|
||||
|
||||
<-s.doneChan
|
||||
|
||||
if err := s.router.UnregisterNode(); err != nil {
|
||||
logger.Errorw("could not unregister node", err)
|
||||
}
|
||||
|
||||
// wait for shutdown
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
defer cancel()
|
||||
@@ -203,7 +199,20 @@ func (s *LivekitServer) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *LivekitServer) Stop() {
|
||||
func (s *LivekitServer) Stop(force bool) {
|
||||
// wait for all participants to exit
|
||||
s.router.PreStop()
|
||||
partTicker := time.NewTicker(5 * time.Second)
|
||||
waitingForParticipants := !force && s.roomManager.HasParticipants()
|
||||
for waitingForParticipants {
|
||||
select {
|
||||
case <-partTicker.C:
|
||||
logger.Infow("waiting for participants to exit")
|
||||
waitingForParticipants = s.roomManager.HasParticipants()
|
||||
}
|
||||
}
|
||||
partTicker.Stop()
|
||||
|
||||
if !s.running.TrySet(false) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// Code generated by Wire. DO NOT EDIT.
|
||||
|
||||
//go:generate go run github.com/google/wire/cmd/wire
|
||||
//+build !wireinject
|
||||
//go:build !wireinject
|
||||
// +build !wireinject
|
||||
|
||||
package service
|
||||
|
||||
|
||||
Reference in New Issue
Block a user