golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.87k stars 748 forks source link

vscode locks on storage.json on ubuntu 22.04 when a new folder is opened #2387

Closed ymolists closed 1 month ago

ymolists commented 2 years ago

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
* Run `go version` to get version of Go from _the VS Code integrated terminal_. ``` $go version go version go1.18 linux/amd64 ``` * Run `gopls -v version` to get version of Gopls from _the VS Code integrated terminal_. ``` $gopls -v version Build info ---------- golang.org/x/tools/gopls v0.9.1 golang.org/x/tools/gopls@v0.9.1 h1:SigsTL4Hpv3a6b/a7oPCLRv5QUeSM6PZNdta1oKY4B0= github.com/BurntSushi/toml@v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU= github.com/google/go-cmp@v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= golang.org/x/exp/typeparams@v0.0.0-20220218215828-6cf2b201936e h1:qyrTQ++p1afMkO4DPEeLGq/3oTsdlvdH4vqZUBWzUKM= golang.org/x/mod@v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sys@v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c= golang.org/x/text@v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/tools@v0.1.12-0.20220713141851-7464a5a40219 h1:Ljlba2fVWOA1049JjsKii44g8nZN2GjpxMlzVc8AnQM= golang.org/x/vuln@v0.0.0-20220613164644-4eb5ba49563c h1:r5bbIROBQtRRgoutV8Q3sFY58VzHW6jMBYl48ANSyS4= honnef.co/go/tools@v0.3.2 h1:ytYb4rOqyp1TSa2EPvNVwtPQJctSELKaMyLfqNP4+34= mvdan.cc/gofumpt@v0.3.0 h1:kTojdZo9AcEYbQYhGuLf/zszYthRdhDNDUi2JKTxas4= mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc= go: go1.18 ``` * Run `code -v` or `code-insiders -v` to get version of VS Code or VS Code Insiders. ``` VS Code version: Code - Insiders 1.70.0-insider (1259bfe0090ac90afbf5d53335c43761de6bb19f, 2022-08-02T05:49:33.165Z) OS version: Linux x64 5.15.0-41-generic Modes: |Item|Value| |---|---| |CPUs|AMD Ryzen 9 5950X 16-Core Processor (32 x 2200)| |GPU Status|2d_canvas: unavailable_software
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: disabled_software
multiple_raster_threads: enabled_on
opengl: disabled_off
rasterization: disabled_software
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: disabled_software
video_encode: disabled_software
vulkan: disabled_off
webgl: unavailable_software
webgl2: unavailable_software| |Load (avg)|0, 1, 1| |Memory (System)|62.71GB (17.26GB free)| |Process Argv|--disable-gpu --user-data-dir /home/ymo/3rdp/dev/vscode/wspace/code-insider-pf-go/data --extensions-dir /home/ymo/3rdp/dev/vscode/wspace/code-insider-pf-go/extensions --crash-reporter-id da3b3803-c43d-46d0-b343-c2d7550834e4| |Screen Reader|no| |VM|0%| |DESKTOP_SESSION|i3| |XDG_CURRENT_DESKTOP|i3| |XDG_SESSION_DESKTOP|i3| |XDG_SESSION_TYPE|x11| ``` * Check your installed extensions to get the version of the VS Code Go extension Extension|Author (truncated)|Version ``` go|gol|0.35.1 cuelang|nic|0.0.1 material-theme|zhu|3.15.2 ``` * Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > `Go: Locate Configured Go Tools` command. ``` Checking configured tools.... GOBIN: /home/ymo/3rdp/dev/golang/releases/golatest-packages/bin toolsGopath: gopath: /home/ymo/3rdp/dev/golang/releases/golatest-packages GOROOT: /home/ymo/3rdp/dev/golang/releases/golatest PATH: /home/ymo/3rdp/dev/golang/releases/golatest/bin:/home/ymo/3rdp/dev/golang/releases/golatest-packages/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin go: /home/ymo/3rdp/dev/golang/releases/golatest/bin/go: go version go1.18 linux/amd64 gotests: /home/ymo/3rdp/dev/golang/releases/golatest-packages/bin/gotests (version: v1.6.0 built with go: go1.18) gomodifytags: /home/ymo/3rdp/dev/golang/releases/golatest-packages/bin/gomodifytags (version: v1.16.0 built with go: go1.18) impl: /home/ymo/3rdp/dev/golang/releases/golatest-packages/bin/impl (version: v1.1.0 built with go: go1.18) goplay: /home/ymo/3rdp/dev/golang/releases/golatest-packages/bin/goplay (version: v1.0.0 built with go: go1.18) dlv: /home/ymo/3rdp/dev/golang/releases/golatest-packages/bin/dlv (version: v1.9.0 built with go: go1.18) staticcheck: /home/ymo/3rdp/dev/golang/releases/golatest-packages/bin/staticcheck (version: v0.3.3 built with go: go1.18) gopls: /home/ymo/3rdp/dev/golang/releases/golatest-packages/bin/gopls (version: v0.9.1 built with go: go1.18) go env Workspace Folder (case-002): /home/ymo/3rdp/dev/vscode/support/case-002 GO111MODULE="" GOARCH="amd64" GOBIN="/home/ymo/3rdp/dev/golang/releases/golatest-packages/bin" GOCACHE="/home/ymo/.cache/go-build" GOENV="/home/ymo/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/ymo/3rdp/dev/golang/releases/golatest-packages/pkg/mod" GONOPROXY="github.com/unnug" GONOSUMDB="github.com/unnug" GOOS="linux" GOPATH="/home/ymo/3rdp/dev/golang/releases/golatest-packages" GOPRIVATE="github.com/unnug" GOPROXY="https://proxy.golang.org,direct" GOROOT="/home/ymo/3rdp/dev/golang/releases/golatest" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/home/ymo/3rdp/dev/golang/releases/golatest/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.18" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/dev/null" GOWORK="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3139709138=/tmp/go-build -gno-record-gcc-switches" ```

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file. Share all the settings with the go. or ["go"] or gopls prefixes.

  // go settings
  "go.useLanguageServer": true,

  "[go]": {
    "editor.tabSize": 2,
    "editor.insertSpaces": true,

    // "editor.snippetSuggestions": "none",

    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
      "source.organizeImports": true
    },

        "editor.rulers": [
            {
                "column": 80,
                "color": "#2d3764",
            }
        ]
  },

Describe the bug

This really feels like a concurrency bug on the file system

This is how i run vscode

  export GOROOT="/home/ymo/3rdp/dev/golang/releases/golatest"
  export GOPKGS="/home/ymo/3rdp/dev/golang/releases/golatest-packages"
  export GOPATH="${GOPKGS}"
  export GOBIN="${GOPATH}/bin"
  export PATH="${GOROOT}/bin:${GOBIN}:${HTSHELL2X_PATH}"

  strace -DD -qq -e trace=file -o /home/ymo/3rdp/dev/vscode/wspace/code-insider-pf-go/logs/code-insiders.trace \
    /home/ymo/3rdp/dev/vscode/releases/code-insider-latest/code-insiders \
    --verbose \
    --user-data-dir \
    /home/ymo/3rdp/dev/vscode/wspace/code-insider-pf-go/data \
    --extensions-dir \
    /home/ymo/3rdp/dev/vscode/wspace/code-insider-pf-go/extensions \
     | tee /home/ymo/3rdp/dev/vscode/wspace/code-insider-pf-go/logs/code-insiders.verbose.log ${@} 

The expectation was that i should be able to open a new window

I am attaching the strace and verbose log i was able to attain. I hope someone can see why this locsk contention is happening

Steps to reproduce the behavior:

The problem is that there is so far no easy way to reproduce this bug. It always happens agter i open a new folder but i cant tell when or how to reproduce it consistently :-(

ymolists commented 2 years ago

I am attaching the verbose log as well as the strace logs in the hhope that someone can see why the contention is happening. This particular is versy short because i was to reproduce the bug as soon as vscode was open.

vscode-insiders.tar.gz

hyangah commented 2 years ago

@ymolists I don't know how Go extension is related to storage.json (what is that file?) Do you see this issue only if Go extension is enabled?

ymolists commented 2 years ago

@hyangah I was only able to reproduce it while i had vscode running with the golang extensions. I normally have one vscode only with golang (via the --extions cli options) as such i am sure there are no other extions that could be posing this problem

I attached a screenshot of htop while this issue was happening below. Is it normal to have that many gopls process running ?

htop-2022-08-03 .

hyangah commented 2 years ago

@ymolists htop lists userland threads by default. (shift+H disables it). Assuming you are running multi-core, I think this is normal. (Go runtime uses multiple threads and actively schedule goroutines on top of them)

Go commands and gopls scan file system imo somewhat aggressively, but I don't think they are doing anything special for storage.json file. cc @findleyr

You said you wish you could open a new window - what do you mean? Did vscode hang, or crash?

ymolists commented 2 years ago

You said you wish you could open a new window - what do you mean? Did vscode hang, or crash?

It hangs if i try to open a folder or if i try to add a folder to the existing workspace. I did not found an easy reproducible way to make it happen consistently after clearing up the vscode data directory. But once it happens it keeps happening after 1 or 2 tries.

BTW if you feel this is best serviced by moving this to the vscode repo i am absolutely fine with it. I downgraded my vscode to older stable version and will update this bug if it keeps happening with older versions of vscode. That could mean the issue is with latest gopls version but not in a conclusive way.

Thank you all and best regards

ymolists commented 2 years ago

The same issue seems to be still happening with this older version

Issue Type: Bug

VS Code version: Code 1.69.0 (92d25e35d9bf1a6b16f7d0758f25d48ace11e5b9, 2022-07-07T08:29:47.439Z) OS version: Linux x64 5.15.0-41-generic Restricted Mode: No

System Info |Item|Value| |---|---| |CPUs|AMD Ryzen 9 5950X 16-Core Processor (32 x 3122)| |GPU Status|2d_canvas: unavailable_software
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: disabled_software
multiple_raster_threads: enabled_on
opengl: disabled_off
rasterization: disabled_software
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: disabled_software
video_encode: disabled_software
vulkan: disabled_off
webgl: unavailable_software
webgl2: unavailable_software| |Load (avg)|0, 1, 1| |Memory (System)|62.71GB (14.10GB free)| |Process Argv|--disable-gpu --user-data-dir /home/ymo/3rdp/dev/vscode/wspace/code-stable-shell/data --extensions-dir /home/ymo/3rdp/dev/vscode/wspace/code-stable-shell/extensions --crash-reporter-id 5247fd83-435d-4ace-9f93-1f642986f968| |Screen Reader|no| |VM|0%| |DESKTOP_SESSION|i3| |XDG_CURRENT_DESKTOP|i3| |XDG_SESSION_DESKTOP|i3| |XDG_SESSION_TYPE|x11|
Extensions (2) Extension|Author (truncated)|Version ---|---|--- go|gol|0.35.1 material-theme|zhu|3.15.2
A/B Experiments ``` vsliv368:30146709 vsreu685:30147344 python383:30185418 vspor879:30202332 vspor708:30202333 vspor363:30204092 vstes627:30244334 vslsvsres303:30308271 pythonvspyl392:30443607 vserr242:30382549 pythontb:30283811 vsjup518:30340749 pythonvspyt551:30345470 pythonptprofiler:30281270 vshan820:30294714 vstes263:30335439 vscorecescf:30445987 pythondataviewer:30285071 vscod805:30301674 binariesv615:30325510 bridge0708:30335490 bridge0723:30353136 vsaa593cf:30376535 vsc1dst:30438360 pythonvs932:30410667 wslgetstarted:30449410 vscscmwlcmt:30465135 cppdebug:30492333 pylanb8912:30529769 vsclangdc:30486549 c4g48928:30535728 dsvsc012cf:30540253 ```

htop-2022-08-04

@hyangah i hope this satisfies removal of the WaitingForInfo label.

findleyr commented 2 years ago

@ymolists can you clarify why you think this is related to storage.json. Specifically, I see the locking in your code-insiders.verbose.log, but in what way is it abnormal? Does it only occur if the vscode-go extension is used?

The same issue seems to be still happening with this older version

Sorry, are you referring to an older version of VS Code, vscode-go, or gopls? Does this occur if you use the stable VS Code distribution, instead of insiders?

ymolists commented 2 years ago

@findleyr it actually only happens when i have the go extension on. I only enable verbose.log for reporting this error. Can you share why you think the lock is on verbose.log please ?

I am only switching between multiple versions of vscode. code-insiders and code-stable.

findleyr commented 2 years ago

@ymolists sorry I meant that I looked at your code-insiders.verbose.log, and see the locking on storage.json, but I don't understand why we should conclude that this is a problem.

hyangah commented 1 month ago

the storage.json file is the central place the vscode keeps various metadata including open files and folders, various settings and configurations for UI (extensions including the go extension also contribute to them). Locking/unlocking around this global resource makes sense to me. This is a low-level internal mechanism, not visible to us. If you think this is too excessive and causes actual issues that prevents usage of vscode, please open an issue to github.com/microsoft/vscode-go. Thanks.