fix(webrtc): 修复异常 ICE 会话导致的端口资源泄漏 - #4782
Conversation
Add configurable ICE UDP session expiry, complete TURN allocation lifecycle cleanup, synchronize the relay registry, correct Allocation Mismatch to 437, and document the timeout setting. Plan-Item: ICEBUGFIX
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 90ec32207a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
PR 概述修复公网部署时异常 ICE 会话导致的 UDP 端口和资源泄漏问题。涉及 TURN allocation 生命周期管理、ICE 会话超时清理、循环引用修复等。 变更分析
发现的问题1.
|
|
@taotaobujue2008 上述是千问3.7max的评论 您看下有没有改进空间? |
baigao-X
left a comment
There was a problem hiding this comment.
LGTM! 感谢补充修正,上述意见您看下是否可以优化下。
Use Ticker for ICE idle tracking, validate TURN allocation ownership and retransmissions, and add allocation regression coverage. Plan-Item: ICEBUGFIX-REVIEW
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7833e00e4d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR hardens the WebRTC ICE/TURN implementation against abnormal or malicious ICE sessions that can linger and leak UDP sessions and TURN relay ports, by introducing idle timeouts and more robust TURN allocation lifecycle management.
Changes:
- Added
iceSessionTimeoutSecconfiguration (default 60s) and enforced UDP ICE session idle shutdown to reclaim resources. - Improved TURN allocation handling: allocation mismatch handling (437), refresh/release logic, periodic allocation timeout cleanup, and removal of relay-session registry races via mutex protection.
- Added a dedicated TURN allocation behavior test (
test_turn_allocation) and updated test filtering when WebRTC target is unavailable.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| webrtc/WebRtcTransport.h | Declares new config key kIceSessionTimeoutSec. |
| webrtc/WebRtcTransport.cpp | Defines new config key and default value in ini initialization. |
| webrtc/USAGE.md | Documents iceSessionTimeoutSec usage. |
| webrtc/StunPacket.hpp | Corrects TURN Allocation Mismatch error code to 437. |
| webrtc/IceTransport.hpp | Extends IceServer with allocation lifecycle helpers, weak refs, and timeout hooks. |
| webrtc/IceTransport.cpp | Implements TURN allocation timeout cleanup, safer relay forwarding, and adds mutex for relay registry. |
| webrtc/IceSession.hpp | Adds an activity ticker to track UDP session idleness. |
| webrtc/IceSession.cpp | Resets activity ticker on receive; closes idle UDP sessions while respecting active allocations. |
| tests/test_turn_allocation.cpp | Adds coverage for Allocate/Refresh behavior, mismatch handling, and capacity failures. |
| tests/CMakeLists.txt | Skips the new test when WebRTC target is not built. |
| conf/config.ini | Adds documented iceSessionTimeoutSec setting to the shipped config. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@baigao-X 看起来可以合并pr了? |
|
会导致 TURN relay 会在 600 秒后中断。 |
公网部署时,ICE 端口可能遭受恶意请求或扫描。异常会话长期不退出,
导致 UDP 会话、TURN relay 端口及关联资源无法及时释放,最终可能耗尽
可用端口。
Plan-Item: ICEBUGFIX