From 95b0a9962861b2aef4a3e9538dd38608aca4bcfc Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 16 Mar 2026 04:33:36 +0200 Subject: Document lock ordering, fix test data races, correct stateMu guard - Add doc comments clarifying Server.mu and completionState.stateMu are independent (no ordering constraint). - Fix test using wrong lock (s.mu instead of stateMu) for lastLLMCall. - Replace time.Sleep polling in 7 tests with s.inflight.Wait() to eliminate data races under -race. Co-Authored-By: Claude Opus 4.6 --- internal/lsp/server.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'internal/lsp/server.go') diff --git a/internal/lsp/server.go b/internal/lsp/server.go index c039255..0cede98 100644 --- a/internal/lsp/server.go +++ b/internal/lsp/server.go @@ -32,11 +32,14 @@ type Server struct { statusSink StatusSink exited atomic.Bool inflight sync.WaitGroup // tracks background goroutines (inline prompt, chat, etc.) - mu sync.RWMutex - docs map[string]*document - logContext bool - configStore *runtimeconfig.Store - cfg appconfig.App + // mu protects docs, cfg, logContext, configLoadOpts, nextID, and chatSubsystem.lastInput. + // It is never held while completionState.stateMu is held, and vice versa, + // so there is no lock ordering concern between them. + mu sync.RWMutex + docs map[string]*document + logContext bool + configStore *runtimeconfig.Store + cfg appconfig.App codeActionSubsystem chatSubsystem // LLM request stats — atomic to avoid taking the server-wide mu lock. -- cgit v1.2.3