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
|
|
@ -26,6 +26,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/modelcontextprotocol/go-sdk/auth"
|
||||
|
|
@ -1515,9 +1516,13 @@ var (
|
|||
// reconnectInitialDelay is the base delay for the first reconnect attempt.
|
||||
//
|
||||
// Mutable for testing.
|
||||
reconnectInitialDelay = 1 * time.Second
|
||||
reconnectInitialDelay atomic.Int64
|
||||
)
|
||||
|
||||
func init() {
|
||||
reconnectInitialDelay.Store(int64(1 * time.Second))
|
||||
}
|
||||
|
||||
// Connect implements the [Transport] interface.
|
||||
//
|
||||
// The resulting [Connection] writes messages via POST requests to the
|
||||
|
|
@ -2196,7 +2201,7 @@ func calculateReconnectDelay(attempt int) time.Duration {
|
|||
return 0
|
||||
}
|
||||
// Calculate the exponential backoff using the grow factor.
|
||||
backoffDuration := time.Duration(float64(reconnectInitialDelay) * math.Pow(reconnectGrowFactor, float64(attempt-1)))
|
||||
backoffDuration := time.Duration(float64(reconnectInitialDelay.Load()) * math.Pow(reconnectGrowFactor, float64(attempt-1)))
|
||||
// Cap the backoffDuration at maxDelay.
|
||||
backoffDuration = min(backoffDuration, reconnectMaxDelay)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue