hide-org / hide

🤖 Headless IDE for AI agents
https://hide.sh
MIT License
112 stars 5 forks source link

Race condition during shutdown #75

Closed artmoskvin closed 1 month ago

artmoskvin commented 1 month ago

Sometimes the shutdown fails with:

fatal error: concurrent map read and map write

goroutine 70 [running]:
github.com/artmoskvin/hide/pkg/lsp.(*ServiceImpl).updateDiagnostics(...)
    /Users/artemm/Code/hide/pkg/lsp/service.go:280
github.com/artmoskvin/hide/pkg/lsp.(*ServiceImpl).listenForDiagnostics(0x140002222a0, {0x14000096800, 0xa}, 0x140002c6690)
    /Users/artemm/Code/hide/pkg/lsp/service.go:274 +0x190
created by github.com/artmoskvin/hide/pkg/lsp.(*ServiceImpl).StartServer in goroutine 21
    /Users/artemm/Code/hide/pkg/lsp/service.go:117 +0x9a4

...

I suspect that the culprit is the diagnostics map that we use to store project diagnostics. During shutdown, we remove all diagnostics and terminate LSP server processes. Apparently, one of the last steps for LSP server before termination is to send empty diagnostics (presumable to clean up all highlights in text editors) which results in the concurrent access conflicting with the shutdown procedure.

artmoskvin commented 1 month ago

Fixed by #76