MCPcopy Create free account
hub / github.com/dan-v/lambda-nat-proxy / checkForPromotion

Method checkForPromotion

internal/manager/manager.go:568–612  ·  view source on GitHub ↗

checkForPromotion monitors a secondary session and promotes it when ready

(ctx context.Context, secondary *Session)

Source from the content-addressed store, hash-verified

566
567// checkForPromotion monitors a secondary session and promotes it when ready
568func (cm *ConnManager) checkForPromotion(ctx context.Context, secondary *Session) {
569 defer func() {
570 if r := recover(); r != nil {
571 shared.LogErrorf("ConnManager: Panic in checkForPromotion: %v", r)
572 }
573 }()
574
575 // Wait longer for the secondary to establish health and verify multiple health checks
576 healthCheckCount := 0
577 ticker := time.NewTicker(5 * time.Second)
578 defer ticker.Stop()
579
580 timeout := time.NewTimer(45 * time.Second) // Increased from 20s
581 defer timeout.Stop()
582
583 for {
584 select {
585 case <-timeout.C:
586 shared.LogInfof("ConnManager: Secondary session %s promotion timeout reached", secondary.ID)
587 return
588 case <-ctx.Done():
589 return
590 case <-secondary.QuicConn.Context().Done():
591 shared.LogInfof("ConnManager: Secondary session %s closed before promotion", secondary.ID)
592 return
593 case <-ticker.C:
594 if secondary.IsHealthy() {
595 healthCheckCount++
596 shared.LogInfof("ConnManager: Secondary session %s health check %d/3 passed", secondary.ID, healthCheckCount)
597
598 // Require 3 consecutive successful health checks before promotion
599 if healthCheckCount >= 3 {
600 shared.LogInfof("ConnManager: Promoting secondary session %s to primary", secondary.ID)
601 cm.promoteSecondary(secondary)
602 return
603 }
604 } else {
605 // Reset counter if health check fails
606 if healthCheckCount > 0 {
607 healthCheckCount = 0
608 }
609 }
610 }
611 }
612}
613
614// promoteSecondary promotes a secondary session to primary
615func (cm *ConnManager) promoteSecondary(secondary *Session) {

Callers 1

Calls 4

promoteSecondaryMethod · 0.95
LogErrorfFunction · 0.92
LogInfofFunction · 0.92
IsHealthyMethod · 0.80

Tested by

no test coverage detected