mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-23 05:06:16 -06:00
[bugfix] Return useful err on server start failure
This commit is contained in:
parent
829143d263
commit
85d4994b96
5 changed files with 73 additions and 50 deletions
|
|
@ -22,6 +22,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
|
|
@ -117,9 +118,11 @@ var Start action.GTSAction = func(ctx context.Context) error {
|
|||
)
|
||||
|
||||
defer func() {
|
||||
// Stop caches with
|
||||
// background tasks.
|
||||
state.Caches.Stop()
|
||||
if state.Caches.Inited() {
|
||||
// We reached a point where caches
|
||||
// were initialized. Stop them.
|
||||
state.Caches.Stop()
|
||||
}
|
||||
|
||||
if route != nil {
|
||||
// We reached a point where the API router
|
||||
|
|
@ -133,6 +136,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 {
|
||||
|
|
@ -240,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(),
|
||||
})
|
||||
|
|
@ -617,3 +629,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