Skip to content

tport: send responses on the incoming connection when reuse-connections is off#330

Open
garacil wants to merge 1 commit into
freeswitch:masterfrom
garacil:fix-309-response-reuse
Open

tport: send responses on the incoming connection when reuse-connections is off#330
garacil wants to merge 1 commit into
freeswitch:masterfrom
garacil:fix-309-response-reuse

Conversation

@garacil

@garacil garacil commented Jul 5, 2026

Copy link
Copy Markdown

With reuse-connections disabled (tp_reusable == 0), tport_tsend() computed reuse = 0 and then fresh = fresh || !reuse, forcing a fresh connection even when the caller handed it the exact live secondary transport to send on — for example nta sending a response on the very connection the request arrived on (tport_tsend(irq->irq_tport, ...)). The stack then tried to open a new connection to the peer's ephemeral source port, which fails, so the response was never sent.

tp_reusable should govern whether a connection may be reused for other destinations; it must not prevent sending on the exact connection the caller passed in.

This distinguishes an inherited tp_reusable == 0 from an explicit per-send TPTAG_REUSE(0):

  • adds tport_is_live_secondary() — the clear-to-send predicate without the tp_reusable requirement (registered, not closed, not send-closed);
  • inherited reuse == 0 no longer forces fresh when self is the exact live secondary; an explicit TPTAG_REUSE(0) (or a self that is not a live secondary) still does, and TPTAG_FRESH is unchanged;
  • the exact-secondary send branch uses tport_is_live_secondary(self).

Outgoing connection-reuse policy is preserved: the reuse search (tport_by_name / tport_by_addrinfo) still skips non-reusable connections, and a caller-provided outgoing tport is still guarded by tport_is_clear_to_send() in nta. No ABI/API change.

Fixes #309.

With reuse-connections disabled (tp_reusable == 0), tport_tsend() computed
reuse = 0 and then fresh = fresh || !reuse, forcing a fresh connection even
when the caller handed it the exact live secondary transport to send on -
e.g. nta sending a response on the connection the request arrived on. The
stack then tried to open a new connection to the peer's ephemeral source
port, which fails, so the response was never sent (freeswitch#309).

tp_reusable governs whether a connection may be reused for other
destinations; it must not prevent sending on the exact connection the caller
passed in. Distinguish an inherited tp_reusable == 0 from an explicit
per-send TPTAG_REUSE(0): only the latter (or a self that is not a live
secondary) forces a fresh connection. Add tport_is_live_secondary()
(clear-to-send without the tp_reusable requirement) and use it for the
exact-secondary send path. The reuse search (tport_by_name/by_addrinfo) and
the client user-tport guard (nta.c) still require tp_reusable, so outgoing
connection-reuse policy is unchanged.

Fixes freeswitch#309.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TPTAG_REUSE: disabling connection reuse causes responses not to be sent

1 participant