Skip to content

ICE: Dedupe servers and track the server index on STUN and TURN requests - #438

Open
kwy404 wants to merge 1 commit into
ValveSoftware:masterfrom
kwy404:ice-dedupe-stun-servers
Open

kwy404 wants to merge 1 commit into
ValveSoftware:masterfrom
kwy404:ice-dedupe-stun-servers

Conversation

@kwy404

@kwy404 kwy404 commented Sep 24, 2026 •

Copy link
Copy Markdown

When a STUN binding or TURN Allocate request timed out, the native ICE client found the current server by address and moved to the next entry, so a list with a repeated address (for example several hostnames resolving to one IP) kept retrying the same entry forever. Duplicate addresses are now skipped when building the STUN and TURN server lists (keeping the first TURN entry's credentials), and each request carries the index of its server so discovery, keepalive and TURN failover always move forward. Adds failure tests that list the dead STUN server and the dead TURN server twice and check that each is tried only once.

Fixes #437

@tintinhamans

Copy link
Copy Markdown

TURN has the same bug: STUNRequestCallback_AllocateRelay finds the current server with index_of( m_vecTURNServers, addr ), so A, A loops forever. Dedupe fits TURN less well since credentials are per entry. Tracking the server index on the request would fix both.

@tintinhamans

Copy link
Copy Markdown

Thanks for the quick update, I just had a quick look and then noticed:

  • Keepalive still uses index_of, so without the dedupe, A, A, B never reaches B.
  • TURN credentials are also looked up by address (401 retry, refresh), so duplicate entries never get their own credentials anyway.

Maybe keep the dedupe for both as well as the index tracking.

@kwy404 kwy404 changed the title ICE: Skip duplicate STUN server addresses ICE: Track the server index on STUN and TURN requests Sep 25, 2026
@kwy404

kwy404 commented Sep 25, 2026

Copy link
Copy Markdown
Author

@tintinhamans Thanks, good point. Switched to tracking the server index on the request in a7693c1 (plus 6924dbc for the keepalive path), so the STUN and TURN retry paths move to the next entry even when addresses repeat, and the dedupe is gone.

Tests: added a TURN case next to the STUN one, listing the dead TURN server twice. Both use a longer connection timeout so a third attempt would show up: on upstream master they fail (12 retransmits and 4 allocate sends instead of 8 and 2), and with this change they pass. test_crypto, test_connection suite-quick, the other STUN/TURN failure cases and the TURN refresh relay test also pass on Windows (MSVC).

@kwy404

kwy404 commented Sep 25, 2026

Copy link
Copy Markdown
Author

@tintinhamans Thanks, good points. Keepalive was already switched to the tracked index in 6924dbc, and ff69e70 brings back the dedupe for both STUN and TURN, keeping the first entry's credentials for TURN since those are looked up by address. The index tracking stays so failover always moves forward. The duplicate entry tests now expect the dead server to be tried only once, and they still fail on master.

@kwy404 kwy404 changed the title ICE: Track the server index on STUN and TURN requests ICE: Dedupe servers and track the server index on STUN and TURN requests Sep 25, 2026

@tintinhamans tintinhamans left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, maybe squash

When the same STUN or TURN server address was listed more than once, the
failover path found the current server with index_of() on its address, so it
kept landing on the first copy and retried the same dead server forever.

Skip duplicate addresses when the STUN and TURN server lists are built (for
TURN the first entry keeps its credentials, since they are looked up by
address), and store the server index on each request so binding, allocate and
keepalive failover always advance to the next entry.

Fixes ValveSoftware#437
@kwy404
kwy404 force-pushed the ice-dedupe-stun-servers branch from ff69e70 to 1e819e3 Compare September 25, 2026 06:04
@kwy404

kwy404 commented Sep 25, 2026

Copy link
Copy Markdown
Author

Thanks for the review. Squashed into a single commit (1e819e3), the code is unchanged.

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.

Native ICE STUN failover can stall when server entries share an address

2 participants