revert(ims): stop asking the SMSC to flush its queue

Both prompts rested on the premise that a rejected RP-ACK makes the SMSC
hold later messages behind the unacknowledged one. Measurement refuted
it: report status shows no correlation with the delay of the messages
that follow, and the delays traced to registration blackouts instead.

Observed on the only two firings. The short message had already been
decoded and notified before the prompt went out, and the sole inbound
MESSAGE that followed was the network's report for the prompt itself,
not a released message. An unsolicited MO carries its own cost: it
already produced a defect where we rejected that report with 488.

The TS 24.341 5.3.2.5 path stays, so RP-SMMA still goes out when memory
becomes available after we denied a message, along with the record that
matches the network's report for it.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
yibaibaandCursor committed 2026-09-02 20:45:43 +08:00
1 parent 28fa5b683e
commit 0b4c440113
7 files changed
+1 -136

No files matched your search

@@ -250,13 +250,6 @@ func (s *Service) acceptProtectedSIP(listener net.Listener) {
return
}
s.resetPortSFlowStats()
if s.portSPushLost.CompareAndSwap(true, false) {
s.networkDone.Add(1)
go func() {
defer s.networkDone.Done()
s.promptSMSCRedeliveryAfterPushRecovery()
}()
}
s.networkDone.Add(1)
go s.serveProtectedSIPConnection(conn)
}
@@ -288,9 +281,6 @@ func (s *Service) handleProtectedServerPushClosed() {
if remaining > 0 {
return
}
// Any MT delivery the network attempted on the dead flow is lost, so mark
// the flow for an RP-SMMA prompt once port-s is back.
s.portSPushLost.Store(true)
logging.Info("IMS protected server push closed; wait for port-s reconnect",
"device", s.DeviceID(), "grace", s.portSReconnectWait(),
"ok_writes", s.portSWriteOK.Load(), "failed_writes", s.portSWriteErr.Load(),
@@ -43,9 +43,6 @@ const (
rpReportInitialDelay = 0
rpReportRetryDelay = time.Second
rpReportMaxAttempts = 4
// One prompt covers every message the SMSC releases in the same flush,
// so rate limit it rather than sending one per rejected report.
smmaPromptMinInterval = time.Minute
)
type mtAckAudit struct {
@@ -148,59 +145,9 @@ func (s *Service) sendRPReportWithRetry(report rpReportRequest) {
"IMS RP report delivery failed",
"device", deviceID, "attempts", attempts,
"rp_mr", int(report.RPMR), "error", err)
s.promptSMSCRedeliveryAfterRejectedReport(err)
}
}
// A rejected delivery report leaves the SMSC believing the short message is
// still outstanding, so it holds later messages behind it until its own
// retransmission timer fires — observed at 13 to 66 minutes. RP-SMMA is the
// only receiver-initiated way to ask for that queue now (TS 24.011 clears
// MCEF and alerts the service centre), so send one instead of waiting.
func (s *Service) promptSMSCRedeliveryAfterRejectedReport(reportErr error) {
if rpReportRejectStatus(reportErr) == 0 {
return
}
s.promptSMSCRedelivery("a rejected report")
}
// promptSMSCRedeliveryAfterPushRecovery runs when port-s comes back after the
// P-CSCF dropped it. Whatever the network was pushing over the dead flow is
// gone, and the SMSC only retries on its own timer — measured at 13 to 30
// minutes — so ask for the queue as soon as the flow is usable again.
func (s *Service) promptSMSCRedeliveryAfterPushRecovery() {
// Same gate as RFC 5626 flow recovery in portSReconnectWatchFired: the
// REGISTER binding has to be live before anything is worth sending.
if s == nil || s.RegState() != regRegistered {
return
}
s.promptSMSCRedelivery("a push connection reset")
}
func (s *Service) promptSMSCRedelivery(reason string) {
if s == nil || s.stopped() || !s.reserveSMMAPrompt(time.Now()) {
return
}
s.smsSendMu.Lock()
err := s.sendRPSMMA()
s.smsSendMu.Unlock()
if err != nil {
logging.RunDebug("IMS RP-SMMA redelivery prompt failed",
"device", s.DeviceID(), "reason", reason, "error", err)
return
}
logging.Info("IMS RP-SMMA sent to release the SMSC queue",
"device", s.DeviceID(), "reason", reason)
}
func (s *Service) reserveSMMAPrompt(now time.Time) bool {
last := s.smmaPromptLastAt.Load()
if last != 0 && now.Sub(time.Unix(0, last)) < smmaPromptMinInterval {
return false
}
return s.smmaPromptLastAt.CompareAndSwap(last, now.UnixNano())
}
func (s *Service) sendRPReportWithRetryPolicy(
report rpReportRequest,
initialDelay time.Duration,
@@ -219,7 +219,7 @@ func TestReportForOurRPSMMAIsAccepted(t *testing.T) {
service.transport.DeliverResponse(registerResponseForRequest(raw, 202, nil))
return nil
})
if err := service.sendRPSMMA(); err != nil {
if err := service.NotifySMSMemoryAvailable(); err != nil {
t.Fatal(err)
}
if smmaCallID == "" {
@@ -352,72 +352,6 @@ func TestRPAckKeepsInReplyToAndStopsOn488(t *testing.T) {
}
}
func TestRejectedRPAckPromptsSMMARedelivery(t *testing.T) {
service, _, _ := newInboundSMSTestService(t)
var bodies [][]byte
service.transport.SetSendFn(func(raw string) error {
_, body, _ := strings.Cut(raw, "\r\n\r\n")
bodies = append(bodies, []byte(body))
status := 488
if smscodec.ClassifyRPDU([]byte(body)).Kind == smscodec.RPDUKindSMMA {
status = 202
}
service.transport.DeliverResponse(registerResponseForRequest(raw, status, nil))
return nil
})
raw := inboundSMSRequest(t, imsSMSContentType, inboundRPData(t, 0x41, "+447700900123", "ack"))
service.sendRPReportWithRetry(rpReportRequest{
Inbound: raw, Body: smscodec.BuildRPAck(0x41), RPMR: 0x41,
})
if len(bodies) != 2 {
t.Fatalf("sent %d requests, want the RP-ACK and an RP-SMMA prompt", len(bodies))
}
if kind := smscodec.ClassifyRPDU(bodies[1]).Kind; kind != smscodec.RPDUKindSMMA {
t.Fatalf("second request RPDU = %q, want RP-SMMA", kind)
}
// One prompt per flush: a second rejection inside the window stays quiet.
before := len(bodies)
service.sendRPReportWithRetry(rpReportRequest{
Inbound: raw, Body: smscodec.BuildRPAck(0x42), RPMR: 0x42,
})
if got := len(bodies) - before; got != 1 {
t.Fatalf("second rejection sent %d requests, want only the RP-ACK", got)
}
}
func TestPushConnectionRecoveryPromptsSMMARedelivery(t *testing.T) {
service, _, _ := newInboundSMSTestService(t)
// Keep RFC 5626 flow recovery out of the way; this test only covers the prompt.
service.portSReconnectGrace = time.Hour
var bodies [][]byte
service.transport.SetSendFn(func(raw string) error {
_, body, _ := strings.Cut(raw, "\r\n\r\n")
bodies = append(bodies, []byte(body))
service.transport.DeliverResponse(registerResponseForRequest(raw, 202, nil))
return nil
})
service.handleProtectedServerPushClosed()
if !service.portSPushLost.Load() {
t.Fatal("a closed push flow did not arm the RP-SMMA prompt")
}
service.promptSMSCRedeliveryAfterPushRecovery()
if len(bodies) != 1 {
t.Fatalf("sent %d requests, want one RP-SMMA prompt", len(bodies))
}
if kind := smscodec.ClassifyRPDU(bodies[0]).Kind; kind != smscodec.RPDUKindSMMA {
t.Fatalf("prompt RPDU = %q, want RP-SMMA", kind)
}
// Vodafone resets port-s several times an hour; one prompt per window.
service.promptSMSCRedeliveryAfterPushRecovery()
if len(bodies) != 1 {
t.Fatalf("sent %d requests, want the prompt to stay rate limited", len(bodies))
}
}
func TestRPAckUsesPAINotFrom(t *testing.T) {
service, _, _ := newInboundSMSTestService(t)
var requests []string
@@ -106,7 +106,6 @@ type messagingRuntime struct {
smmaSent map[string]time.Time
moSelfHealLastAt atomic.Int64
smmaPromptLastAt atomic.Int64
lastMTAckMu sync.Mutex
}
@@ -42,10 +42,6 @@ func (s *Service) NotifySMSMemoryAvailable() error {
return s.sendRPSMMAWithRetryPolicy(rpReportInitialDelay, rpReportRetryDelay)
}
func (s *Service) sendRPSMMA() error {
return s.sendRPSMMAWithRetryPolicy(rpReportInitialDelay, rpReportRetryDelay)
}
func (s *Service) sendRPSMMAWithRetryPolicy(initialDelay, retryDelay time.Duration) error {
if !s.waitSMSRetryDelay(initialDelay) {
return errRPReportAborted
@@ -183,7 +183,6 @@ type Service struct {
protectedConnMu sync.Mutex
protectedConns map[net.Conn]struct{}
portSReconnectGrace time.Duration
portSPushLost atomic.Bool
portSWriteOK atomic.Int64
portSWriteErr atomic.Int64
portSLastWriteOKAt atomic.Int64