TEL-562: improve correctness of media timeout - #683
Merged
Conversation
dennwc
approved these changes
May 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three improvements:
lastPacketTimewas zero (no packet ever received),time.Since(lastPacketTime)overflowedtime.Durationand logged as~9.22e9s. NowsinceLastis0when there has been no packet.sinceLastexceeding the general timeout whenisInitial:false. When media flowed briefly during the initial window and then stopped, the loop slept until the full initial deadline (e.g. 30s) before re-evaluating, at which pointlastPacketTimewas already older than the general timeout (e.g.sinceLast=20.3swithtimeout=15). Fixed by capping the timer arm at the general timeout. This is not a regression. The previous media timeout mechanism has the same problem, e.g. last packet arrives at 9.7s then stopped. The first ticker triggers at 15s and then again at 15s. The "real" timeout is 20.3s.isInitialflipping back totruemid-call afterSetTimeout.isInitial := lastPacketTime.Before(startTime)was relative to the most recently re-armedstartTime, so the no-ACK fallback(SetTimeout(min(3s, MediaTimeoutInitial), MediaTimeout))caused calls that had already received RTP to be re-classified as initial and killed by the shortened 3s window, producing logs likeisInitial:true, packets:38, sinceLast:5.16s. Changed toisInitial := lastPacketTime.IsZero().isInitialnow means "no media has ever been received on this port." Policy change: once media is flowing, the no-ACK fallback no longer triggers the 3s shortcut. The call is killed only after the general 15s window of silence from the last packet. Signaling faults no longer aggressively tear down calls whose media is healthy.datadog log: https://app.datadoghq.com/logs?query=%22triggering%20media%20timeout%22%20region%3Aofrankfurt1b&agg_m=count&agg_m_source=base&agg_t=count&clustering_pattern_field_path=message&cols=host%2Cservice%2C%40sinceLast%2C%40isInitial%2Cimage_tag%2C%40sinceStart%2C%40timeout&messageDisplay=inline&refresh_mode=paused&storage=hot&stream_sort=desc&viz=stream&from_ts=1778596320000&to_ts=1778610600000&live=false