mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 04:42:25 -05:00
[bugfix] Return useful err on server start failure (#3879)
* [bugfix] Return useful err on `server start` failure * remove scheduler started func * remove tryUntil
This commit is contained in:
parent
310319dc0e
commit
d0ae8f6231
9 changed files with 86 additions and 81 deletions
|
|
@ -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).
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue