summaryrefslogtreecommitdiff
path: root/internal/cache
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2025-03-05 19:12:53 +0100
committerLibravatar tobi <tobi.smethurst@protonmail.com>2025-03-11 09:43:26 +0100
commitd0ae8f6231d4d5d71e48df356b3f4655fbc95add (patch)
tree2fb00c6270f82d2e5afe8fd6700da8cf913f67a8 /internal/cache
parent[chore] fixed email template to align with the new "Log in" button + separate... (diff)
downloadgotosocial-d0ae8f6231d4d5d71e48df356b3f4655fbc95add.tar.xz
[bugfix] Return useful err on `server start` failure (#3879)
* [bugfix] Return useful err on `server start` failure * remove scheduler started func * remove tryUntil
Diffstat (limited to 'internal/cache')
-rw-r--r--internal/cache/cache.go21
-rw-r--r--internal/cache/util.go18
2 files changed, 12 insertions, 27 deletions
diff --git a/internal/cache/cache.go b/internal/cache/cache.go
index 5771b4e95..41bef488c 100644
--- a/internal/cache/cache.go
+++ b/internal/cache/cache.go
@@ -23,6 +23,7 @@ import (
"codeberg.org/gruf/go-cache/v3/ttl"
"github.com/superseriousbusiness/gotosocial/internal/cache/headerfilter"
"github.com/superseriousbusiness/gotosocial/internal/config"
+ "github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/log"
)
@@ -125,16 +126,18 @@ func (c *Caches) Init() {
// Start will start any caches that require a background
// routine, which usually means any kind of TTL caches.
-func (c *Caches) Start() {
+func (c *Caches) Start() error {
log.Infof(nil, "start: %p", c)
- tryUntil("starting webfinger cache", 5, func() bool {
- return c.Webfinger.Start(5 * time.Minute)
- })
+ if !c.Webfinger.Start(5 * time.Minute) {
+ return gtserror.New("could not start webfinger cache")
+ }
- tryUntil("starting statusesFilterableFields cache", 5, func() bool {
- return c.StatusesFilterableFields.Start(5 * time.Minute)
- })
+ if !c.StatusesFilterableFields.Start(5 * time.Minute) {
+ return gtserror.New("could not start statusesFilterableFields cache")
+ }
+
+ return nil
}
// Stop will stop any caches that require a background
@@ -142,8 +145,8 @@ func (c *Caches) Start() {
func (c *Caches) Stop() {
log.Infof(nil, "stop: %p", c)
- tryUntil("stopping webfinger cache", 5, c.Webfinger.Stop)
- tryUntil("stopping statusesFilterableFields cache", 5, c.StatusesFilterableFields.Stop)
+ _ = c.Webfinger.Stop()
+ _ = c.StatusesFilterableFields.Stop()
}
// Sweep will sweep all the available caches to ensure none
diff --git a/internal/cache/util.go b/internal/cache/util.go
index fde2f9ada..ceb053e34 100644
--- a/internal/cache/util.go
+++ b/internal/cache/util.go
@@ -19,11 +19,9 @@ package cache
import (
"errors"
- "time"
errorsv2 "codeberg.org/gruf/go-errors/v2"
"github.com/superseriousbusiness/gotosocial/internal/db"
- "github.com/superseriousbusiness/gotosocial/internal/log"
)
// SentinelError is an error that can be returned and checked against to indicate a non-permanent
@@ -51,19 +49,3 @@ type nocopy struct{}
func (*nocopy) Lock() {}
func (*nocopy) Unlock() {}
-
-// tryUntil will attempt to call 'do' for 'count' attempts, before panicking with 'msg'.
-func tryUntil(msg string, count int, do func() bool) {
- for i := 0; i < count; i++ {
- if do() {
- // success.
- return
- }
-
- // Sleep for a little before retry (a bcakoff).
- time.Sleep(time.Millisecond * 1 << (i + 1))
- }
-
- // panic on total failure as this shouldn't happen.
- log.Panicf(nil, "failed %s after %d tries", msg, count)
-}