diff --git a/third_party/vowifi-go/internal/vowifi/imscore/port_s_session.go b/third_party/vowifi-go/internal/vowifi/imscore/port_s_session.go index d21fd93e..b502ad53 100644 --- a/third_party/vowifi-go/internal/vowifi/imscore/port_s_session.go +++ b/third_party/vowifi-go/internal/vowifi/imscore/port_s_session.go @@ -127,11 +127,13 @@ func (s *Service) recordPortSClosed(conn net.Conn, err error, now time.Time) boo kind = portSCloseSARetired } // Retired cleanup must not replace the latest failure. An older live - // connection still matters if it is the final downlink on this registrar. + // connection still matters if it is the final downlink on this registrar, + // unless it went with the old SAs after a newer flow had opened. relevant := tracked && strings.EqualFold(registrar, currentRegistrar) current := relevant && (connection.generation == s.portSSession.generation || - (kind != portSCloseLocal && !s.hasLivePortSConnectionLocked(currentRegistrar))) + (kind != portSCloseLocal && kind != portSCloseSARetired && + !s.hasLivePortSConnectionLocked(currentRegistrar))) if current { if kind != portSCloseLocal { s.udpDownlinkProven.Store(false) diff --git a/third_party/vowifi-go/internal/vowifi/imscore/refresh_security_switch_test.go b/third_party/vowifi-go/internal/vowifi/imscore/refresh_security_switch_test.go index 53306ee1..2b574412 100644 --- a/third_party/vowifi-go/internal/vowifi/imscore/refresh_security_switch_test.go +++ b/third_party/vowifi-go/internal/vowifi/imscore/refresh_security_switch_test.go @@ -560,3 +560,30 @@ func TestRetiredPortSFlowAwaitsTheNewSAs(t *testing.T) { t.Fatal("SMS readiness requires the retired port-s flow") } } + +// Retiring the old SAs closes the old port-s flow; when a newer flow has +// already failed, that failure stays the one recovery acts on. +func TestRetiredOldFlowKeepsNewFlowFailure(t *testing.T) { + svc, _, _, _, _ := switchRefreshService(t, 200, switchedSecurityServer) + if _, _, err := svc.runRegisterAttempt(context.Background()); err != nil { + t.Fatalf("refresh: %v", err) + } + portS := func(remotePort int) net.Conn { + pipe, pcscf := net.Pipe() + t.Cleanup(func() { pcscf.Close() }) + conn := addressedConn{Conn: pipe, + local: &net.TCPAddr{IP: net.IPv4(10, 0, 0, 2), Port: 41001}, + remote: &net.TCPAddr{IP: net.IPv4(10, 0, 0, 1), Port: remotePort}} + if !svc.trackProtectedPortSConnection(conn, time.Now()) { + t.Fatal("port-s flow not tracked") + } + return conn + } + oldFlow, newFlow := portS(16381), portS(16382) + svc.recordPortSClosed(newFlow, syscall.ECONNRESET, time.Now()) + svc.markPortSSARetired(oldFlow) + svc.recordPortSClosed(oldFlow, io.EOF, time.Now()) + if got := svc.capturePortSSession().lastCloseKind; got != portSClosePeerReset { + t.Fatalf("close kind = %q, want the new flow's %q", got, portSClosePeerReset) + } +}