@@ -888,6 +888,17 @@ func (sm *SessionManager) UpdateLastActive(sessionID string) {
888888func (sm * SessionManager ) validateSinglePrimary () {
889889 primarySessions := make ([]* Session , 0 )
890890
891+ sm .logger .Debug ().
892+ Int ("sm.sessions_len" , len (sm .sessions )).
893+ Interface ("sm.sessions_keys" , func () []string {
894+ keys := make ([]string , 0 , len (sm .sessions ))
895+ for k := range sm .sessions {
896+ keys = append (keys , k )
897+ }
898+ return keys
899+ }()).
900+ Msg ("validateSinglePrimary: checking sm.sessions map" )
901+
891902 // Find all sessions that think they're primary
892903 for _ , session := range sm .sessions {
893904 if session .Mode == SessionModePrimary {
@@ -952,35 +963,16 @@ func (sm *SessionManager) validateSinglePrimary() {
952963 }
953964
954965 // Check if there's an active grace period for any primary session
955- // BUT: if grace period just started (within 2 seconds), allow immediate promotion
956966 hasActivePrimaryGracePeriod := false
957967 for sessionID , graceTime := range sm .reconnectGrace {
958968 if time .Now ().Before (graceTime ) {
959969 if reconnectInfo , hasInfo := sm .reconnectInfo [sessionID ]; hasInfo {
960970 if reconnectInfo .Mode == SessionModePrimary {
961- // Calculate how long ago the grace period started
962- gracePeriod := 10
963- if currentSessionSettings != nil && currentSessionSettings .ReconnectGrace > 0 {
964- gracePeriod = currentSessionSettings .ReconnectGrace
965- }
966- graceStartTime := graceTime .Add (- time .Duration (gracePeriod ) * time .Second )
967- timeSinceGraceStart := time .Since (graceStartTime )
968-
969- // If grace period just started (within 2 seconds), allow immediate promotion
970- // This enables instant promotion on logout while still protecting against network blips
971- if timeSinceGraceStart > 2 * time .Second {
972- hasActivePrimaryGracePeriod = true
973- sm .logger .Debug ().
974- Str ("gracePrimaryID" , sessionID ).
975- Dur ("remainingGrace" , time .Until (graceTime )).
976- Dur ("timeSinceGraceStart" , timeSinceGraceStart ).
977- Msg ("Active grace period detected for primary session - blocking auto-promotion" )
978- } else {
979- sm .logger .Debug ().
980- Str ("gracePrimaryID" , sessionID ).
981- Dur ("timeSinceGraceStart" , timeSinceGraceStart ).
982- Msg ("Grace period just started - allowing immediate promotion" )
983- }
971+ hasActivePrimaryGracePeriod = true
972+ sm .logger .Debug ().
973+ Str ("gracePrimaryID" , sessionID ).
974+ Dur ("remainingGrace" , time .Until (graceTime )).
975+ Msg ("Active grace period detected for primary session - blocking auto-promotion" )
984976 break
985977 }
986978 }
0 commit comments