bridgev2: stop disappearing message loop on shutdown
Some checks are pending
Go / Lint (latest) (push) Waiting to run
Go / Build (old, libolm) (push) Waiting to run
Go / Build (latest, libolm) (push) Waiting to run
Go / Build (old, goolm) (push) Waiting to run
Go / Build (latest, goolm) (push) Waiting to run

This commit is contained in:
Tulir Asokan 2025-04-30 15:33:33 +03:00
commit 58e4d0f2cc
2 changed files with 12 additions and 5 deletions

View file

@ -318,6 +318,7 @@ func (br *Bridge) Stop() {
func (br *Bridge) stop(isRunOnce bool) {
br.Log.Info().Msg("Shutting down bridge")
br.DisappearLoop.Stop()
br.stopBackfillQueue.Set()
br.Matrix.PreStop()
if !isRunOnce {

View file

@ -8,6 +8,7 @@ package bridgev2
import (
"context"
"sync/atomic"
"time"
"github.com/rs/zerolog"
@ -21,15 +22,17 @@ import (
type DisappearLoop struct {
br *Bridge
NextCheck time.Time
stop context.CancelFunc
stop atomic.Pointer[context.CancelFunc]
}
const DisappearCheckInterval = 1 * time.Hour
func (dl *DisappearLoop) Start() {
log := dl.br.Log.With().Str("component", "disappear loop").Logger()
ctx := log.WithContext(context.Background())
ctx, dl.stop = context.WithCancel(ctx)
ctx, stop := context.WithCancel(log.WithContext(context.Background()))
if oldStop := dl.stop.Swap(&stop); oldStop != nil {
(*oldStop)()
}
log.Debug().Msg("Disappearing message loop starting")
for {
dl.NextCheck = time.Now().Add(DisappearCheckInterval)
@ -49,8 +52,11 @@ func (dl *DisappearLoop) Start() {
}
func (dl *DisappearLoop) Stop() {
if dl.stop != nil {
dl.stop()
if dl == nil {
return
}
if stop := dl.stop.Load(); stop != nil {
(*stop)()
}
}