Skip to content

Commit

Permalink
[chore] Silence memlimit package (#3002)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
daenney and tsmethurst authored Jun 13, 2024
1 parent 38cd889 commit 3c86bd8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions cmd/gotosocial/action/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 3c86bd8

Please sign in to comment.