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
|
|
@ -635,6 +635,17 @@ public:
|
|||
// What was read and not yet dispatched goes with the flow: nothing
|
||||
// read from it can be answered once it is closed.
|
||||
void Close() { if (fd_ >= 0) { close(fd_); fd_ = -1; } alive_ = false; fb_ = {}; }
|
||||
// Close without the FIN's exchange: the kernel drops the connection at
|
||||
// once (after the peer's FIN with a reset in our FIN's place; where a
|
||||
// reset or its own giving up has ended it, it sends nothing), so the
|
||||
// same local port can connect to the same peer again in the same
|
||||
// breath. A socket closed with Close() after the peer's FIN stays in the
|
||||
// kernel's table until the peer has acknowledged ours, and a connect from
|
||||
// its port meanwhile is refused (EADDRNOTAVAIL). For a dead flow only.
|
||||
void Abort() {
|
||||
if (fd_ >= 0) { linger l{1, 0}; setsockopt(fd_, SOL_SOCKET, SO_LINGER, &l, sizeof l); }
|
||||
Close();
|
||||
}
|
||||
private:
|
||||
// One read of the socket once poll(2) has named it: `m` is the message a
|
||||
// datagram held (UDP); on TCP the bytes go to the frame buffer. False
|
||||
|
|
@ -1658,6 +1669,7 @@ public:
|
|||
MaybeRefresh();
|
||||
MaybeReconnect();
|
||||
MaybeResubscribe();
|
||||
MaybeResendInvite();
|
||||
if (!call_ && sip_.Alive() && Mono() - lastKa_ > 30) { sip_.SendKeepalive(); lastKa_ = Mono(); }
|
||||
ReapMedia();
|
||||
if (call_ && call_->State() != imsd::engine::CallState::Active && Mono() > deadline_) {
|
||||
|
|
@ -2664,6 +2676,30 @@ private:
|
|||
else ReconnectCycle();
|
||||
}
|
||||
|
||||
// A client flow found dead under an outgoing call whose INVITE has had
|
||||
// no response and no CANCEL (CallMachine::Unanswered) is reopened once
|
||||
// per attempt and the INVITE sent again: a flow the network had
|
||||
// forgotten is reset at the first bytes sent on it, and those may be a
|
||||
// call's. No REGISTER goes first: the registration and its SAs stand
|
||||
// (not where the network has ended the binding: RegRecovery's
|
||||
// Reconnectable, and then nothing is reopened), and TS 33.203 7.1 has a
|
||||
// UE that has no TCP connection towards the P-CSCF set one up before it
|
||||
// sends a request. One connect, which waits 12 s for an answer; where
|
||||
// it fails, and where the flow dies again under the resent INVITE, the
|
||||
// call ends (CallMachine::OnFlowLost), and the recovery policy takes
|
||||
// the flow up when the call is gone (MaybeReconnect).
|
||||
void MaybeResendInvite() {
|
||||
if (!call_ || sip_.Alive() || !call_->Unanswered()) return;
|
||||
bool ok = false;
|
||||
if (recovery_.Reconnectable() && call_->ResendDue()) {
|
||||
Log(std::format("call {}: the client flow died before any response to the INVITE; reopening it", call_->Uni()));
|
||||
sip_.Abort();
|
||||
ok = sip_.Connect(local_, PortUc, pcscf_, portPs_, transport_, /*tries=*/1) && Execute(call_->OnFlowReopened());
|
||||
}
|
||||
if (!ok && call_ && !call_->Terminated()) Execute(call_->OnFlowLost());
|
||||
MaybeDropCall();
|
||||
}
|
||||
|
||||
// The policy's next step, as the journal line: what, and when.
|
||||
std::string NextStep() {
|
||||
auto plan = recovery_.Next(Boot());
|
||||
|
|
|
|||
Loading…
Reference in a new issue