From 5c0ceec2a62e2c1003aa72b4fa78bb09e53c3a84 Mon Sep 17 00:00:00 2001 From: Till <2353100+S7evinK@users.noreply.github.com> Date: Tue, 9 Apr 2024 07:49:56 +0200 Subject: [PATCH] Don't attempt to send transactions if Dendrite is shutting down (#3356) This should avoid confusions with logs like: ``` time="2024-04-08T08:38:45.104235081Z" level=error msg="Failed to set \"scs.ems.host\" as assumed offline" func="github.com/matrix-org/dendrite/federationapi/statistics.(*ServerStatistics).Failure" file="github.com/matrix-org/dendrite/federationapi/statistics/statistics.go:204" error="sqlutil.WithTransaction.Begin: sql: database is closed" time="2024-04-08T08:38:45.104239201Z" level=error msg="Failed to set \"obermui.de\" as assumed offline" func="github.com/matrix-org/dendrite/federationapi/statistics.(*ServerStatistics).Failure" file="github.com/matrix-org/dendrite/federationapi/statistics/statistics.go:204" error="sqlutil.WithTransaction.Begin: sql: database is closed" ``` or ``` time="2024-04-08T08:38:45.105235411Z" level=error msg="Failed to get pending EDUs for \"retro76.net\"" func="github.com/matrix-org/dendrite/federationapi/queue.(*destinationQueue).getPendingFromDatabase" file="github.com/matrix-org/dendritefederationapi/queue/destinationqueue.go:258" error="sqlutil.WithTransaction.Begin: sql: database is closed" ``` [skip ci] --- federationapi/queue/destinationqueue.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/federationapi/queue/destinationqueue.go b/federationapi/queue/destinationqueue.go index f51e849f..87a6fe55 100644 --- a/federationapi/queue/destinationqueue.go +++ b/federationapi/queue/destinationqueue.go @@ -294,6 +294,10 @@ func (oq *destinationQueue) checkNotificationsOnClose() { // backgroundSend is the worker goroutine for sending events. func (oq *destinationQueue) backgroundSend() { + // Don't try to send transactions if we are shutting down. + if oq.process.Context().Err() != nil { + return + } // Check if a worker is already running, and if it isn't, then // mark it as started. if !oq.running.CompareAndSwap(false, true) {