diff options
| author | 2025-03-05 19:12:53 +0100 | |
|---|---|---|
| committer | 2025-03-11 09:43:26 +0100 | |
| commit | d0ae8f6231d4d5d71e48df356b3f4655fbc95add (patch) | |
| tree | 2fb00c6270f82d2e5afe8fd6700da8cf913f67a8 /cmd | |
| parent | [chore] fixed email template to align with the new "Log in" button + separate... (diff) | |
| download | gotosocial-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 'cmd')
| -rw-r--r-- | cmd/gotosocial/action/admin/account/account.go | 4 | ||||
| -rw-r--r-- | cmd/gotosocial/action/admin/media/list.go | 4 | ||||
| -rw-r--r-- | cmd/gotosocial/action/admin/media/prune/common.go | 4 | ||||
| -rw-r--r-- | cmd/gotosocial/action/server/server.go | 64 |
4 files changed, 68 insertions, 8 deletions
diff --git a/cmd/gotosocial/action/admin/account/account.go b/cmd/gotosocial/action/admin/account/account.go index 7dfb6b1d4..aa241177d 100644 --- a/cmd/gotosocial/action/admin/account/account.go +++ b/cmd/gotosocial/action/admin/account/account.go @@ -38,7 +38,9 @@ import ( func initState(ctx context.Context) (*state.State, error) { var state state.State state.Caches.Init() - state.Caches.Start() + if err := state.Caches.Start(); err != nil { + return nil, fmt.Errorf("error starting caches: %w", err) + } // Only set state DB connection. // Don't need Actions or Workers for this (yet). diff --git a/cmd/gotosocial/action/admin/media/list.go b/cmd/gotosocial/action/admin/media/list.go index a017539ed..e80c0da51 100644 --- a/cmd/gotosocial/action/admin/media/list.go +++ b/cmd/gotosocial/action/admin/media/list.go @@ -125,7 +125,9 @@ func setupList(ctx context.Context) (*list, error) { } state.Caches.Init() - state.Caches.Start() + if err := state.Caches.Start(); err != nil { + return nil, fmt.Errorf("error starting caches: %w", err) + } // Only set state DB connection. // Don't need Actions or Workers for this. diff --git a/cmd/gotosocial/action/admin/media/prune/common.go b/cmd/gotosocial/action/admin/media/prune/common.go index d73676f5b..fce445fb0 100644 --- a/cmd/gotosocial/action/admin/media/prune/common.go +++ b/cmd/gotosocial/action/admin/media/prune/common.go @@ -42,7 +42,9 @@ func setupPrune(ctx context.Context) (*prune, error) { var state state.State state.Caches.Init() - state.Caches.Start() + if err := state.Caches.Start(); err != nil { + return nil, fmt.Errorf("error starting caches: %w", err) + } // Scheduler is required for the // cleaner, but no other workers diff --git a/cmd/gotosocial/action/server/server.go b/cmd/gotosocial/action/server/server.go index dcd30a9b5..18f3be3e2 100644 --- a/cmd/gotosocial/action/server/server.go +++ b/cmd/gotosocial/action/server/server.go @@ -22,6 +22,7 @@ import ( "errors" "fmt" "net/http" + "net/netip" "os" "os/signal" "runtime" @@ -116,8 +117,9 @@ var Start action.GTSAction = func(ctx context.Context) error { ) defer func() { - // Stop caches with - // background tasks. + // Stop any started caches. + // + // Noop if never started. state.Caches.Stop() if route != nil { @@ -132,6 +134,8 @@ var Start action.GTSAction = func(ctx context.Context) error { // Stop any currently running // worker processes / scheduled // tasks from being executed. + // + // Noop on unstarted workers. state.Workers.Stop() if state.Timelines.Home != nil { @@ -201,7 +205,9 @@ var Start action.GTSAction = func(ctx context.Context) error { // Initialize caches state.Caches.Init() - state.Caches.Start() + if err := state.Caches.Start(); err != nil { + return fmt.Errorf("error starting caches: %w", err) + } // Open connection to the database now caches started. dbService, err := bundb.NewBunDBService(ctx, state) @@ -239,10 +245,17 @@ var Start action.GTSAction = func(ctx context.Context) error { return fmt.Errorf("error opening storage backend: %w", err) } + // Parse http client allow + // and block range exceptions. + ranges, err := parseClientRanges() + if err != nil { + return err + } + // Prepare wrapped httpclient with config. client := httpclient.New(httpclient.Config{ - AllowRanges: config.MustParseIPPrefixes(config.GetHTTPClientAllowIPs()), - BlockRanges: config.MustParseIPPrefixes(config.GetHTTPClientBlockIPs()), + AllowRanges: ranges.allow, + BlockRanges: ranges.block, Timeout: config.GetHTTPClientTimeout(), TLSInsecureSkipVerify: config.GetHTTPClientTLSInsecureSkipVerify(), }) @@ -609,3 +622,44 @@ func compileWASM(ctx context.Context) error { return nil } + +func parseClientRanges() ( + *struct { + allow []netip.Prefix + block []netip.Prefix + }, + error, +) { + parseF := func(ips []string, ranges []netip.Prefix, flag string) error { + for i, ip := range ips { + p, err := netip.ParsePrefix(ip) + if err != nil { + return fmt.Errorf("error parsing %s value %s: %w", flag, ip, err) + } + ranges[i] = p + } + return nil + } + + allowIPs := config.GetHTTPClientAllowIPs() + allowRanges := make([]netip.Prefix, len(allowIPs)) + allowFlag := config.HTTPClientAllowIPsFlag() + if err := parseF(allowIPs, allowRanges, allowFlag); err != nil { + return nil, err + } + + blockIPs := config.GetHTTPClientBlockIPs() + blockRanges := make([]netip.Prefix, len(blockIPs)) + blockFlag := config.HTTPClientBlockIPsFlag() + if err := parseF(blockIPs, blockRanges, blockFlag); err != nil { + return nil, err + } + + return &struct { + allow []netip.Prefix + block []netip.Prefix + }{ + allow: allowRanges, + block: blockRanges, + }, nil +} |
