A recent test flake on windows produced this error

            found matching log "2025/06/24 15:24:17 creating temp dir: mkdir C:\\b\\s\\w\\ir\\x\\t\\gopls-3472.1: Cannot create a file when that file already exists.\n"

which implicates this (old) code in server.Initialize:

    // For uniqueness, use the gopls PID rather than params.ProcessID (the client
    // pid). Some clients might start multiple gopls servers, though they
    // probably shouldn't.
    pid := os.Getpid()
    s.tempDir = filepath.Join(os.TempDir(), fmt.Sprintf("gopls-%d.%s", pid, s.session.ID()))
    err := os.Mkdir(s.tempDir, 0700)
    if err != nil {
        // MkdirTemp could fail due to permissions issues. This is a problem with
        // the user's environment, but should not block gopls otherwise behaving.
        // All usage of s.tempDir should be predicated on having a non-empty
        // s.tempDir.
        event.Error(ctx, "creating temp dir", err)
        s.tempDir = ""
    }

Either this code is not robust to routine PID recycling (which should be rare in a builder), or a single gopls process has two sessions numbered 1. (Or both). I wonder whether recent MCP work has increased the latter probability.

Either way, the fix is to use os.MkdirTemp.

Comment From: gopherbot

Change https://go.dev/cl/683995 mentions this issue: gopls/internal/server: remove tempDir field