imsd: when the client flow is found dead before any response to a call's INVITE, one reconnect and the INVITE again, else the call ends
A flow that is dead in a way imsd has not seen yet, the peer having dropped the connection's state, shows itself at the next bytes sent on it, where the peer answers them with a reset. Where those bytes were an outgoing call's INVITE, imsd read the reset, marked the flow dead and did nothing more for the call: no reconnect runs while a call is up, so the attempt stayed in `dialing` until its setup deadline, 90 s, sent a CANCEL that could not go out and was given up 10 s later, where a call that is no emergency call ends (`setup deadline expired`); the flow was reconnected only once the call was gone. Against a stand-in network that forgets a flow after 20 s of silence, 1.2.3's call ended 100 s after the Dial. The engine's loop now takes such a call up (MaybeResendInvite). When the client flow is found dead under an outgoing attempt whose INVITE has had no response, a 100 included, and no CANCEL, the dead socket is closed without a FIN's exchange, the flow is reopened with one connect and the same INVITE is sent again, the setup deadline running from then. Once per attempt: an emergency call's fallback attempt has a resend of its own. The INVITE is the first one byte for byte, its branch included, so a server that did receive the first matches the second to its transaction (RFC 3261 17.2.3). No REGISTER goes first: the registration and its SAs stand, and TS 33.203 7.1 has a UE with no TCP connection towards the P-CSCF set one up before it sends a request. Where a reg-event NOTIFY has ended the binding nothing is reopened. Where nothing is reopened, the connect fails (one that gets no answer, after 12 s) or the flow dies again before a response, the call ends with `error`, an emergency call's first attempt too: there is no flow for its fallback. The recovery policy takes the flow up once the call is gone, as before. The close without a FIN's exchange is for a flow the peer closed: closed the usual way, such a socket stays in the kernel's table until the peer has acknowledged imsd's own FIN, and a connect from its port before that is refused. A reset goes out in the FIN's place there; after a reset or the kernel's own giving up the socket is closed already and nothing is sent; and the reopen runs on a flow already found dead only. The recovery's reconnect closes the usual way, as before, and connects once more 10 s after such a refusal (one is in a user's log on O2, 2026-09-24, in the second the flow was found dead). Not changed: under a call, a flow that died with no reset and no close reaching the phone is found dead only when the kernel gives up on unacknowledged bytes, 924.6 s or more after them by its default tcp_retries2, so an attempt whose own INVITE is the first such bytes gets no response and is cancelled at its setup deadline, as before; a flow found dead after a response to the INVITE is not reopened, as before; a Dial whose INVITE cannot be sent ends its call at once, as before. Tested: tests/Engine (which attempt is sent again, the same bytes, once per attempt, the deadline anew, the call's end where the flow is lost); the daemon of this commit and 1.2.3's on the workstation against a stand-in network (the fp6 journal's 2026-11-24-crlf-keepalive capture, bench-dial.sh): a flow the network forgot, reopened and the INVITE answered 486 as on a live flow, where 1.2.3's call ended after 100 s; a flow the network closed at the INVITE, with the acknowledgement of the daemon's close kept back; one that died on the daemon's side at the kernel's retransmission limit; a network that takes no new connection, one that resets the second INVITE's flow too and one that has ended the binding, where the call ended within a second; UDP. And on the dev phone on KPN, the binary of the range's tip: a call to voicemail answered and hung up, and one whose flow was made to die under the INVITE before the INVITE left the phone: reopened from the same port, the INVITE again 2.1 s after the death was found, answered 0.2 s later. By a call, no P-CSCF that had dropped a flow's state has been met, and none that had received the first INVITE before the flow died.
This commit is contained in:
parent
d3e495c333
commit
0aea0dac7f
4 changed files with 231 additions and 9 deletions
|
|
@ -420,11 +420,49 @@ export namespace imsd::engine {
|
|||
offer.codecs = codecs_;
|
||||
std::string sdp = imsd::sdp::BuildOffer(offer);
|
||||
std::vector<Action> a;
|
||||
a.push_back(Send(imsd::msg::BuildInvite(ctx_, d_, sdp, precond_)));
|
||||
inviteOut_ = imsd::msg::BuildInvite(ctx_, d_, sdp, precond_);
|
||||
a.push_back(Send(inviteOut_));
|
||||
a.push_back(Deadline(InviteTimeout));
|
||||
return a;
|
||||
}
|
||||
|
||||
// The current outgoing attempt has sent its INVITE and has had no
|
||||
// response to it, not a 100 either, and no CANCEL has followed it.
|
||||
// The shell asks when it finds the client flow dead under a call: a
|
||||
// flow the network had forgotten is reset at the first bytes sent
|
||||
// on it, and those may be this INVITE.
|
||||
bool Unanswered() const {
|
||||
return state_ == CallState::Dialing && !inviteOut_.empty() && !answered_ && !cancelled_;
|
||||
}
|
||||
// … and the attempt has not been sent again yet.
|
||||
bool ResendDue() const { return Unanswered() && !resent_; }
|
||||
|
||||
// The shell reopened the flow under an attempt whose resend is due:
|
||||
// the same INVITE again, byte for byte (the same branch: RFC 3261
|
||||
// 17.2.3 has a server that did receive the first match this one to
|
||||
// its transaction), and the setup deadline from now. Once per
|
||||
// attempt.
|
||||
std::vector<Action> OnFlowReopened() {
|
||||
std::vector<Action> a;
|
||||
if (!ResendDue()) return a;
|
||||
resent_ = true;
|
||||
a.push_back(LogAct(std::format("call {}: the INVITE again over the reopened flow", uni_)));
|
||||
a.push_back(Send(inviteOut_));
|
||||
a.push_back(Deadline(InviteTimeout));
|
||||
return a;
|
||||
}
|
||||
|
||||
// The flow under an unanswered attempt is dead and stays so (it
|
||||
// could not be reopened, or died again after the resend): the call
|
||||
// ends here, an emergency call's first attempt too, with nothing to
|
||||
// send a CANCEL on and no flow for a fallback attempt.
|
||||
std::vector<Action> OnFlowLost() {
|
||||
std::vector<Action> a;
|
||||
if (!Unanswered()) return a;
|
||||
Append(a, Finish("error", "the client flow died before any response to the INVITE"));
|
||||
return a;
|
||||
}
|
||||
|
||||
// UAS: answer the inbound INVITE with 100 Trying + 180 Ringing (made
|
||||
// reliable only when the caller Requires 100rel) and arm the ring
|
||||
// timeout. An offer we cannot serve — no audio line, or none of the
|
||||
|
|
@ -499,6 +537,7 @@ export namespace imsd::engine {
|
|||
AbsorbDialog(msg);
|
||||
auto st = imsd::sip::Status(msg);
|
||||
if (!st) return a;
|
||||
answered_ = true;
|
||||
int code = *st;
|
||||
if (code > 100 && code < 200) {
|
||||
if (state_ == CallState::Dialing) {
|
||||
|
|
@ -761,6 +800,12 @@ export namespace imsd::engine {
|
|||
bool sosTried_ = false;
|
||||
bool plainTried_ = false;
|
||||
bool userCancelled_ = false; // CANCEL came from OnHangup, not a deadline
|
||||
// The current outgoing attempt's INVITE as sent, whether any response
|
||||
// to it has come, and whether it went out a second time over a
|
||||
// reopened flow (OnFlowReopened).
|
||||
std::string inviteOut_;
|
||||
bool answered_ = false;
|
||||
bool resent_ = false;
|
||||
std::set<std::string> pracked_;
|
||||
std::string answerSdp_;
|
||||
std::optional<int> dtmfPt_; // the running leg's telephone-event pt, set at media start
|
||||
|
|
@ -781,15 +826,18 @@ export namespace imsd::engine {
|
|||
answerSdp_.clear();
|
||||
cancelled_ = false;
|
||||
userCancelled_ = false;
|
||||
answered_ = false;
|
||||
resent_ = false;
|
||||
}
|
||||
|
||||
// The emergency fallback chain — where the next attempt (if any)
|
||||
// points. `msg` may be empty (deadline paths).
|
||||
// - a sos INVITE that fails for any reason other than the user
|
||||
// hanging up is re-attempted as a plain INVITE of the dialled
|
||||
// digits: the pre-emergency-support behavior, so classification
|
||||
// can only improve on the status quo, never block a call the old
|
||||
// code would have placed.
|
||||
// hanging up, its own send failing at the Dial (Fail) or the
|
||||
// client flow lost under it (OnFlowLost: there is nothing to send
|
||||
// on) is re-attempted as a plain INVITE of the dialled digits: the
|
||||
// pre-emergency-support behavior, so classification can only improve
|
||||
// on the status quo, never block a call the old code would have placed.
|
||||
// - a plain INVITE answered 380 Alternative Service whose body
|
||||
// names emergency (TS 24.229 5.1.6: the network classified a
|
||||
// number we didn't) is re-attempted as urn:service:sos. A 380
|
||||
|
|
|
|||
Loading…
Reference in a new issue