mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
bridgev2: stop disappearing message loop on shutdown
This commit is contained in:
parent
e0b1e9b0d3
commit
58e4d0f2cc
2 changed files with 12 additions and 5 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue