mcp: re-enable race test after fixing data races (#851)

1. (non-test) Don't queue notifications if there are no connected
sessions.
2. Change `reconnectInitialDelay` to be atomic, as it is modified in
tests.
3. Protect map access with mutex in `TestServerTransportCleanup`.
This commit is contained in:
Maciej Kisiel 2026-03-23 08:35:27 +01:00 • committed by GitHub
commit 755b9ed4df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -628,6 +628,14 @@ func (s *Server) changeAndNotify(notification string, change func() bool) {
s.mu.Lock()
defer s.mu.Unlock()
if change() && s.shouldSendListChangedNotification(notification) {
if len(s.sessions) == 0 {
if t := s.pendingNotifications[notification]; t != nil {
t.Stop()
s.pendingNotifications[notification] = nil
}
return
}
// Reset the outstanding delayed call, if any.
if t := s.pendingNotifications[notification]; t == nil {
s.pendingNotifications[notification] = time.AfterFunc(notificationDelay, func() { s.notifySessions(notification) })