Jelajahi Sumber

fix(video): 失败响应按相关键移除SIP订阅

Kazerin 3 minggu lalu
induk
melakukan
1400038485

+ 3 - 1
video-service/src/main/java/com/ruoyi/wvp/gb28181/transmit/SIPProcessorObserver.java

@@ -137,7 +137,9 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
                             SipSubscribe.EventResult<ResponseEvent> eventResult = new SipSubscribe.EventResult<>(responseEvent);
                             sipEvent.getErrorEvent().response(eventResult);
                         }
-                        sipSubscribe.removeSubscribe(callIdHeader.getCallId());
+                        // Remove by the same correlation the success branch used: a bare callId can
+                        // never remove this entry, so a later timeout would fire the error again.
+                        sipSubscribe.removeSubscribe(callIdHeader.getCallId() + cSeqHeader.getSeqNumber());
                     }
                 }
             }

+ 1 - 1
video-service/src/main/java/com/zksy/video/lifecycle/VideoStopReceipts.java

@@ -35,7 +35,7 @@ public class VideoStopReceipts {
         public String ssrc;
         /** Device-chosen SSRC after a real renegotiation; the pool number above stays the return identity. */
         public String negotiatedSsrc;
-        /** The pre-existing legacy path already returned the pool number while negotiating. */
+        /** True only after the token-owned pool number was positively returned. */
         public boolean poolReturned;
         public boolean poolTracked;
         public boolean externalSsrc;

+ 16 - 0
video-service/src/test/java/com/zksy/video/lifecycle/LateSipRecoveryTest.java

@@ -107,6 +107,22 @@ class LateSipRecoveryTest {
         assertNull(external.manager().getSsrcTransactionByStream("rtp", owned.getStream()));
     }
 
+    @Test void failureBranchRemovesTheCorrelatedSubscriptionSoItCannotFireTwice() throws Exception {
+        RedisBytes external = new RedisBytes();
+        com.ruoyi.wvp.gb28181.transmit.SIPProcessorObserver observer = new com.ruoyi.wvp.gb28181.transmit.SIPProcessorObserver();
+        ReflectionTestUtils.setField(observer, "sessionManager", external.manager());
+        com.ruoyi.wvp.gb28181.event.SipSubscribe subscribe = new com.ruoyi.wvp.gb28181.event.SipSubscribe();
+        java.util.concurrent.atomic.AtomicInteger errors = new java.util.concurrent.atomic.AtomicInteger();
+        // Subscriptions are keyed by callId + cseq, exactly like the success branch.
+        subscribe.addSubscribe("call-19", com.ruoyi.wvp.gb28181.event.sip.SipEvent.getInstance("call-19", null,
+                result -> errors.incrementAndGet(), 60000));
+        ReflectionTestUtils.setField(observer, "sipSubscribe", subscribe);
+        observer.processResponse(new javax.sip.ResponseEvent(this, null, null,
+                response("INVITE", "call-1", 9, "z9hG4bK-invite", "to-1", 486)));
+        assertEquals(1, errors.get());
+        assertTrue(subscribe.isEmpty(), "the failed response must remove its own correlated subscription");
+    }
+
     @Test void deletionCasCannotEraseAReplacementFromAnotherServiceInstance() throws Exception {
         RedisBytes external = new RedisBytes(); SipInviteSessionManager sessions = external.manager();
         SsrcTransaction owned = dialog("managed_11111111111111111111111111111111", "call-1"); sessions.put(owned);