Skip to content

Commit 162699f

Browse files
authored
Merge pull request #88 from smart-mcp-proxy/bugfix/100cpu-consuption
Fix tray reconnect spin and honor upstream backoff
2 parents 484b295 + 848a962 commit 162699f

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

cmd/mcpproxy-tray/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,10 @@ func (cpl *CoreProcessLauncher) monitorAPIConnection(ctx context.Context) {
910910
select {
911911
case <-ctx.Done():
912912
return
913-
case connState := <-connectionStateCh:
913+
case connState, ok := <-connectionStateCh:
914+
if !ok {
915+
return
916+
}
914917
switch connState {
915918
case tray.ConnectionStateConnected:
916919
cpl.stateMachine.SendEvent(state.EventAPIConnected)

internal/runtime/lifecycle.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"mcpproxy-go/internal/runtime/configsvc"
1212
)
1313

14+
const connectAttemptTimeout = 45 * time.Second
15+
1416
// StartBackgroundInitialization kicks off configuration sync and background loops.
1517
func (r *Runtime) StartBackgroundInitialization() {
1618
// Phase 6: Start Supervisor for state reconciliation and lock-free reads
@@ -94,7 +96,7 @@ func (r *Runtime) connectAllWithRetry(ctx context.Context) {
9496
if connectedCount < totalCount {
9597
r.UpdatePhaseMessage(fmt.Sprintf("Connected to %d/%d servers, retrying...", connectedCount, totalCount))
9698

97-
connectCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
99+
connectCtx, cancel := context.WithTimeout(ctx, connectAttemptTimeout)
98100
defer cancel()
99101

100102
if err := r.upstreamManager.ConnectAll(connectCtx); err != nil {

internal/upstream/manager.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,13 @@ func (m *Manager) ConnectAll(ctx context.Context) error {
518518
continue
519519
}
520520

521+
if client.Config.Quarantined {
522+
m.logger.Info("Skipping quarantined client",
523+
zap.String("id", id),
524+
zap.String("name", client.Config.Name))
525+
continue
526+
}
527+
521528
// Check connection eligibility with detailed logging
522529
if client.IsConnected() {
523530
m.logger.Debug("Client already connected, skipping",
@@ -533,6 +540,16 @@ func (m *Manager) ConnectAll(ctx context.Context) error {
533540
continue
534541
}
535542

543+
if client.GetState() == types.StateError && !client.ShouldRetry() {
544+
info := client.GetConnectionInfo()
545+
m.logger.Debug("Client backoff active, skipping connect attempt",
546+
zap.String("id", id),
547+
zap.String("name", client.Config.Name),
548+
zap.Int("retry_count", info.RetryCount),
549+
zap.Time("last_retry_time", info.LastRetryTime))
550+
continue
551+
}
552+
536553
m.logger.Info("Attempting to connect client",
537554
zap.String("id", id),
538555
zap.String("name", client.Config.Name),

0 commit comments

Comments
 (0)