Skip to content

x/tools/gopls: HUGE memory leak in gopls. Manual GC works. #72919

Closed as not planned
@hlpmenu

Description

@hlpmenu

gopls version

Build info

golang.org/x/tools/gopls v0.18.1
    golang.org/x/tools/[email protected] h1:2xJBNzdImS5u/kV/ZzqDLSvlBSeZX+pWY9uKVP7Pask=
    github.com/BurntSushi/[email protected] h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs=
    github.com/google/[email protected] h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
    golang.org/x/exp/[email protected] h1:1xaZTydL5Gsg78QharTwKfA9FY9CZ1VQj6D/AZEvHR0=
    golang.org/x/[email protected] h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM=
    golang.org/x/[email protected] h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
    golang.org/x/[email protected] h1:L2k9GUV2TpQKVRGMjN94qfUMgUwOFimSQ6gipyJIjKw=
    golang.org/x/[email protected] h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
    golang.org/x/[email protected] h1:Ja/5gV5a9Vvho3p2NC/T2TtxhHjrWS/2DvCKMvA0a+Y=
    golang.org/x/[email protected] h1:NPGnvPOTgnjBc9HTaUx+nj+EaUYxl5SJOWqaDYGaFYw=
    honnef.co/go/[email protected] h1:4bH5o3b5ZULQ4UrBmP+63W9r7qIkqJClEA9ko5YKx+I=
    mvdan.cc/[email protected] h1:bg91ttqXmi9y2xawvkuMXyvAA/1ZGJqYAEGjXuP0JXU=
    mvdan.cc/xurls/[email protected] h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: go1.24.1

go env

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE='on'
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='[redacted].cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='[redacted].config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1586616623=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='[redacted]go/pkg/mod'
GONOPROXY='github.com/hlpmenu'
GONOSUMDB='gopkg.hlmpn.dev'
GOOS='linux'
GOPATH='[redacted]go'
GOPRIVATE='[redacted]'
GOPROXY='direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='[redacted].config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.1'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Seems to make no difference what you do to trigger it, after startup it starts to creep up about +1-2MB memory a second until hitting close to/oom limit.

Note
Manually triggering a GC seems to actually "gc", but it keeps on climbing back until you manually gc next.
At the point where i just restarted it and it was around 650MB, manually triggering a GC pushed it down to 166MB, where it kept climbing again, and once a new manual gc was triggered, went back to 166MB exactly again.

What did you see happen?

System etc

  • OS: Ubuntu 24.10
  • Kernel: 6.13.7-x64v3-t2-oracular-xanmod1

Start climbing 1-2mb/s right at start, manually triggering a gc frees the memory as you would expect to be done normally.

Malloc calls are consistantly a huge number higher than frees, example :

With no manual gc:
Malloc calls 4,772,278
Frees 212,506

with manual gc, same instance:
Malloc calls 5,251,943
Frees 4,491,204

Process is idle while this is happening, logging shows nothing weird at all.

What did you expect to see?

No memleak lol

Editor and settings

Same thing occurs in vscode+cursor

code:

Version: 1.98.0
Commit: 6609ac3d66f4eade5cf376d1cb76f13985724bcb
Date: 2025-03-04T21:06:18.612Z (1 wk ago)
Browser: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Code/1.98.0 Chrome/132.0.6834.196 Electron/34.2.0 Safari/537.36

cursor:

Version: 0.47.8
Commit: 82ef0f61c01d079d1b7e5ab04d88499d5af500e0
Date: 2025-03-18T05:39:44.386Z (8 hrs ago)
Browser: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Cursor/0.47.8 Chrome/128.0.6613.186 Electron/32.2.6 Safari/537.36

And trough cli.

Vscode go related settings

  "[go]": {

        "editor.defaultFormatter": "golang.go",
        "editor.codeLens": false,
        "go.diagnostic.vulncheck": "Imports",
    },
    "go.enableCodeLens": {
        "runtest": false,
    },

    // ## Linting
    "go.lintOnSave": "package",
    "go.lintTool": "golangci-lint",

    "go.playground": {
        "openbrowser": false,
        "share": false,
        "run": false
    },
    "go.showWelcome": false,
    "go.testExplorer.showOutput": false,
    "go.testExplorer.enable": false,
    "go.survey.prompt": false,
    "go.lintFlags": [
        "--fast"
    ],

    // ## Gopls
    "gopls": {
        "ui.semanticTokens": true,
        "build.directoryFilters": [
            "-node_modules",
            "-.git",
        ]
    },
    "go.toolsEnvVars": {
        "GOGC": "off"
    },

    // ## Formating
    "go.formatTool": "default",

    // ## Go vet 
    "go.vetOnSave": "off",
    "go.vetFlags": [ ],

Logs

Attatchments:

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions