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:
parent
ea161959d7
commit
755b9ed4df
1 changed files with 34 additions and 16 deletions
|
|
@ -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) })
|
||||
|
|
|
|||
Loading…
Reference in a new issue