Go version

6f44cc88f5f94253096ceed16b8e0fdb117cdd06

Output of go env in your module/workspace:

N/A

What did you do?

https://build.golang.org/log/292d4f122d2f2eab97f2bc7e5c07570c4311f17f

What did you see happen?

--- FAIL: TestServer (6.89s)
    testing.go:1231: TempDir RemoveAll cleanup: remove C:\Users\gopher\AppData\Local\Temp\1\TestServer2537943436\001: The process cannot access the file because it is being used by another process.
FAIL
FAIL    golang.org/x/pkgsite/cmd/pkgsite    7.092s

What did you expect to see?

All tests should be passing.

I think this is just a missed Closed call on a file opened in extractReadme.

Comment From: gopherbot

Change https://go.dev/cl/562176 mentions this issue: internal/fetch: close directory file in defer in extractReadme

Comment From: eduzgun

Try running this

t.Cleanup(func() {
        runtime.GC()
})

which will trigger a manual garbage collection. If there are any file handles that were opened but not explicitly closed, the garbage collector will close them once it sees they are no longer being referenced. By calling runtime.GC(), you ensure any lingering open file handles are closed before TempDir naturally tries to clean itself up. It doesn't affect the logic in the test because t.cleanup() will run after the test completes.