From 3c86bd890c54ac6f54f07a5d7c1d3f8d5e399641 Mon Sep 17 00:00:00 2001 From: Daenney Date: Thu, 13 Jun 2024 19:02:48 +0200 Subject: [PATCH] [chore] Silence memlimit package (#3002) The memlimit package started to log any error returned by automemlimit. This updates our implementation to call SetGoMemLimitWithOpts() instead which uses the same defaults as automemlimit except for being initialised with a noop logger. We check the returned error for a particular substring, as when cgroups isn't available even when running on a Linux system that's not a problem. If it's anything but that error, we log it at the warning level so that admins can still diagnose other cgroup related issues. Fixes #2983 Co-authored-by: tobi <31960611+tsmethurst@users.noreply.github.com> --- cmd/gotosocial/action/server/server.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cmd/gotosocial/action/server/server.go b/cmd/gotosocial/action/server/server.go index 24b3771df..14db67795 100644 --- a/cmd/gotosocial/action/server/server.go +++ b/cmd/gotosocial/action/server/server.go @@ -24,9 +24,11 @@ import ( "net/http" "os" "os/signal" + "strings" "syscall" "time" + "github.com/KimMachineGun/automemlimit/memlimit" "github.com/gin-gonic/gin" "github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action" "github.com/superseriousbusiness/gotosocial/internal/api" @@ -60,9 +62,6 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/transport" "github.com/superseriousbusiness/gotosocial/internal/typeutils" "github.com/superseriousbusiness/gotosocial/internal/web" - - // Inherit memory limit if set from cgroup - _ "github.com/KimMachineGun/automemlimit" ) // Start creates and starts a gotosocial server @@ -71,6 +70,12 @@ var Start action.GTSAction = func(ctx context.Context) error { log.Warnf(ctx, "could not set CPU limits from cgroup: %s", err) } + if _, err := memlimit.SetGoMemLimitWithOpts(); err != nil { + if !strings.Contains(err.Error(), "cgroup mountpoint does not exist") { + log.Warnf(ctx, "could not set Memory limits from cgroup: %s", err) + } + } + var ( // Define necessary core variables // before anything so we can prepare