Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
34336429
Unverified
提交
34336429
authored
5月 03, 2024
作者:
Iñaki Baz Castillo
提交者:
GitHub
5月 03, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Worker: Fix memory leak when using WebRtcServer with TCP enabled (#1389)
上级
98cf79eb
隐藏空白字符变更
内嵌
并排
正在显示
18 个修改的文件
包含
188 行增加
和
159 行删除
+188
-159
CHANGELOG.md
CHANGELOG.md
+5
-1
IceServer.hpp
worker/include/RTC/IceServer.hpp
+1
-0
TransportTuple.hpp
worker/include/RTC/TransportTuple.hpp
+1
-23
SignalHandle.hpp
worker/include/handles/SignalHandle.hpp
+3
-1
TcpConnectionHandle.hpp
worker/include/handles/TcpConnectionHandle.hpp
+2
-1
TcpServerHandle.hpp
worker/include/handles/TcpServerHandle.hpp
+1
-1
TimerHandle.hpp
worker/include/handles/TimerHandle.hpp
+3
-1
UdpSocketHandle.hpp
worker/include/handles/UdpSocketHandle.hpp
+1
-1
ChannelSocket.cpp
worker/src/Channel/ChannelSocket.cpp
+1
-1
IceServer.cpp
worker/src/RTC/IceServer.cpp
+9
-0
TransportTuple.cpp
worker/src/RTC/TransportTuple.cpp
+16
-0
WebRtcTransport.cpp
worker/src/RTC/WebRtcTransport.cpp
+2
-2
SignalHandle.cpp
worker/src/handles/SignalHandle.cpp
+19
-19
TcpConnectionHandle.cpp
worker/src/handles/TcpConnectionHandle.cpp
+54
-40
TcpServerHandle.cpp
worker/src/handles/TcpServerHandle.cpp
+25
-25
TimerHandle.cpp
worker/src/handles/TimerHandle.cpp
+15
-15
UdpSocketHandle.cpp
worker/src/handles/UdpSocketHandle.cpp
+26
-26
UnixStreamSocketHandle.cpp
worker/src/handles/UnixStreamSocketHandle.cpp
+4
-2
没有找到文件。
CHANGELOG.md
浏览文件 @
34336429
# Changelog
### NEXT
-
Worker: Fix memory leak when using
`WebRtcServer`
with TCP enabled (
[
PR #1389
](
https://github.com/versatica/mediasoup/pull/1389
)
).
### 3.14.4
-
Worker: Fix crash.
RtcpFeedback
parameter is optional (
[
PR #1387
](
https://github.com/versatica/mediasoup/pull/1387
)
, credits to @Lynnworld).
-
Worker: Fix crash.
`RtcpFeedback`
parameter is optional (
[
PR #1387
](
https://github.com/versatica/mediasoup/pull/1387
)
, credits to @Lynnworld).
### 3.14.3
...
...
worker/include/RTC/IceServer.hpp
浏览文件 @
34336429
...
...
@@ -131,6 +131,7 @@ namespace RTC
std
::
string
password
;
uint16_t
consentTimeoutMs
{
30000u
};
// Others.
bool
destroying
{
false
};
std
::
string
oldUsernameFragment
;
std
::
string
oldPassword
;
IceState
state
{
IceState
::
NEW
};
...
...
worker/include/RTC/TransportTuple.hpp
浏览文件 @
34336429
...
...
@@ -51,29 +51,7 @@ namespace RTC
}
public
:
void
Close
()
{
if
(
this
->
protocol
==
Protocol
::
UDP
)
{
this
->
udpSocket
->
Close
();
}
else
{
this
->
tcpConnection
->
Close
();
}
}
bool
IsClosed
()
{
if
(
this
->
protocol
==
Protocol
::
UDP
)
{
return
this
->
udpSocket
->
IsClosed
();
}
else
{
return
this
->
tcpConnection
->
IsClosed
();
}
}
void
CloseTcpConnection
();
flatbuffers
::
Offset
<
FBS
::
Transport
::
Tuple
>
FillBuffer
(
flatbuffers
::
FlatBufferBuilder
&
builder
)
const
;
...
...
worker/include/handles/SignalHandle.hpp
浏览文件 @
34336429
...
...
@@ -22,9 +22,11 @@ public:
~
SignalHandle
();
public
:
void
Close
();
void
AddSignal
(
int
signum
,
const
std
::
string
&
name
);
private
:
void
InternalClose
();
/* Callbacks fired by UV events. */
public
:
void
OnUvSignal
(
int
signum
);
...
...
worker/include/handles/TcpConnectionHandle.hpp
浏览文件 @
34336429
...
...
@@ -49,7 +49,7 @@ public:
virtual
~
TcpConnectionHandle
();
public
:
void
Close
();
void
Trigger
Close
();
bool
IsClosed
()
const
{
return
this
->
closed
;
...
...
@@ -110,6 +110,7 @@ public:
}
private
:
void
InternalClose
();
bool
SetPeerAddress
();
/* Callbacks fired by UV events. */
...
...
worker/include/handles/TcpServerHandle.hpp
浏览文件 @
34336429
...
...
@@ -17,7 +17,6 @@ public:
~
TcpServerHandle
()
override
;
public
:
void
Close
();
void
Dump
()
const
;
const
struct
sockaddr
*
GetLocalAddress
()
const
{
...
...
@@ -48,6 +47,7 @@ protected:
void
AcceptTcpConnection
(
TcpConnectionHandle
*
connection
);
private
:
void
InternalClose
();
bool
SetLocalAddress
();
/* Pure virtual methods that must be implemented by the subclass. */
...
...
worker/include/handles/TimerHandle.hpp
浏览文件 @
34336429
...
...
@@ -23,7 +23,6 @@ public:
~
TimerHandle
();
public
:
void
Close
();
void
Start
(
uint64_t
timeout
,
uint64_t
repeat
=
0
);
void
Stop
();
void
Reset
();
...
...
@@ -41,6 +40,9 @@ public:
return
uv_is_active
(
reinterpret_cast
<
uv_handle_t
*>
(
this
->
uvHandle
))
!=
0
;
}
private
:
void
InternalClose
();
/* Callbacks fired by UV events. */
public
:
void
OnUvTimer
();
...
...
worker/include/handles/UdpSocketHandle.hpp
浏览文件 @
34336429
...
...
@@ -42,7 +42,6 @@ public:
virtual
~
UdpSocketHandle
();
public
:
void
Close
();
bool
IsClosed
()
const
{
return
this
->
closed
;
...
...
@@ -80,6 +79,7 @@ public:
void
SetRecvBufferSize
(
uint32_t
size
);
private
:
void
InternalClose
();
bool
SetLocalAddress
();
/* Callbacks fired by UV events. */
...
...
worker/src/Channel/ChannelSocket.cpp
浏览文件 @
34336429
...
...
@@ -247,7 +247,7 @@ namespace Channel
return
free
!=
nullptr
;
}
inline
void
ChannelSocket
::
SendImpl
(
const
uint8_t
*
payload
,
uint32_t
payloadLen
)
void
ChannelSocket
::
SendImpl
(
const
uint8_t
*
payload
,
uint32_t
payloadLen
)
{
MS_TRACE_STD
();
...
...
worker/src/RTC/IceServer.cpp
浏览文件 @
34336429
...
...
@@ -112,6 +112,8 @@ namespace RTC
{
MS_TRACE
();
this
->
destroying
=
true
;
// Here we must notify the listener about the removal of current
// usernameFragments (and also the old one if any) and all tuples.
...
...
@@ -223,6 +225,13 @@ namespace RTC
{
MS_TRACE
();
// While IceServer is being destroyed, it may call listener methods that may
// end calling RemoveTuple(). We must ignore it to avoid double-free issues.
if
(
this
->
destroying
)
{
return
;
}
RTC
::
TransportTuple
*
removedTuple
{
nullptr
};
// Find the removed tuple.
...
...
worker/src/RTC/TransportTuple.cpp
浏览文件 @
34336429
...
...
@@ -11,6 +11,8 @@ namespace RTC
TransportTuple
::
Protocol
TransportTuple
::
ProtocolFromFbs
(
FBS
::
Transport
::
Protocol
protocol
)
{
MS_TRACE
();
switch
(
protocol
)
{
case
FBS
:
:
Transport
::
Protocol
::
UDP
:
...
...
@@ -23,6 +25,8 @@ namespace RTC
FBS
::
Transport
::
Protocol
TransportTuple
::
ProtocolToFbs
(
TransportTuple
::
Protocol
protocol
)
{
MS_TRACE
();
switch
(
protocol
)
{
case
TransportTuple
:
:
Protocol
::
UDP
:
...
...
@@ -35,6 +39,18 @@ namespace RTC
/* Instance methods. */
void
TransportTuple
::
CloseTcpConnection
()
{
MS_TRACE
();
if
(
this
->
protocol
==
Protocol
::
UDP
)
{
MS_ABORT
(
"cannot delete a UDP socket"
);
}
this
->
tcpConnection
->
TriggerClose
();
}
flatbuffers
::
Offset
<
FBS
::
Transport
::
Tuple
>
TransportTuple
::
FillBuffer
(
flatbuffers
::
FlatBufferBuilder
&
builder
)
const
{
...
...
worker/src/RTC/WebRtcTransport.cpp
浏览文件 @
34336429
...
...
@@ -1180,9 +1180,9 @@ namespace RTC
}
// If this is a TCP tuple, close its underlaying TCP connection.
if
(
tuple
->
GetProtocol
()
==
RTC
::
TransportTuple
::
Protocol
::
TCP
&&
!
tuple
->
IsClosed
()
)
if
(
tuple
->
GetProtocol
()
==
RTC
::
TransportTuple
::
Protocol
::
TCP
)
{
tuple
->
Close
();
tuple
->
Close
TcpConnection
();
}
}
...
...
worker/src/handles/SignalHandle.cpp
浏览文件 @
34336429
...
...
@@ -31,24 +31,7 @@ SignalHandle::~SignalHandle()
if
(
!
this
->
closed
)
{
Close
();
}
}
void
SignalHandle
::
Close
()
{
MS_TRACE
();
if
(
this
->
closed
)
{
return
;
}
this
->
closed
=
true
;
for
(
auto
*
uvHandle
:
this
->
uvHandles
)
{
uv_close
(
reinterpret_cast
<
uv_handle_t
*>
(
uvHandle
),
static_cast
<
uv_close_cb
>
(
onCloseSignal
));
InternalClose
();
}
}
...
...
@@ -86,7 +69,24 @@ void SignalHandle::AddSignal(int signum, const std::string& name)
this
->
uvHandles
.
push_back
(
uvHandle
);
}
inline
void
SignalHandle
::
OnUvSignal
(
int
signum
)
void
SignalHandle
::
InternalClose
()
{
MS_TRACE
();
if
(
this
->
closed
)
{
return
;
}
this
->
closed
=
true
;
for
(
auto
*
uvHandle
:
this
->
uvHandles
)
{
uv_close
(
reinterpret_cast
<
uv_handle_t
*>
(
uvHandle
),
static_cast
<
uv_close_cb
>
(
onCloseSignal
));
}
}
void
SignalHandle
::
OnUvSignal
(
int
signum
)
{
MS_TRACE
();
...
...
worker/src/handles/TcpConnectionHandle.cpp
浏览文件 @
34336429
...
...
@@ -90,13 +90,13 @@ TcpConnectionHandle::~TcpConnectionHandle()
if
(
!
this
->
closed
)
{
Close
();
Internal
Close
();
}
delete
[]
this
->
buffer
;
}
void
TcpConnectionHandle
::
Close
()
void
TcpConnectionHandle
::
Trigger
Close
()
{
MS_TRACE
();
...
...
@@ -105,41 +105,9 @@ void TcpConnectionHandle::Close()
return
;
}
int
err
;
this
->
closed
=
true
;
// Tell the UV handle that the TcpConnectionHandle has been closed.
this
->
uvHandle
->
data
=
nullptr
;
// Don't read more.
err
=
uv_read_stop
(
reinterpret_cast
<
uv_stream_t
*>
(
this
->
uvHandle
));
if
(
err
!=
0
)
{
MS_ABORT
(
"uv_read_stop() failed: %s"
,
uv_strerror
(
err
));
}
// If there is no error and the peer didn't close its connection side then close gracefully.
if
(
!
this
->
hasError
&&
!
this
->
isClosedByPeer
)
{
// Use uv_shutdown() so pending data to be written will be sent to the peer
// before closing.
auto
*
req
=
new
uv_shutdown_t
;
req
->
data
=
static_cast
<
void
*>
(
this
);
err
=
uv_shutdown
(
req
,
reinterpret_cast
<
uv_stream_t
*>
(
this
->
uvHandle
),
static_cast
<
uv_shutdown_cb
>
(
onShutdown
));
InternalClose
();
if
(
err
!=
0
)
{
MS_ABORT
(
"uv_shutdown() failed: %s"
,
uv_strerror
(
err
));
}
}
// Otherwise directly close the socket.
else
{
uv_close
(
reinterpret_cast
<
uv_handle_t
*>
(
this
->
uvHandle
),
static_cast
<
uv_close_cb
>
(
onCloseTcp
));
}
this
->
listener
->
OnTcpConnectionClosed
(
this
);
}
void
TcpConnectionHandle
::
Dump
()
const
...
...
@@ -366,11 +334,57 @@ void TcpConnectionHandle::ErrorReceiving()
{
MS_TRACE
();
Close
();
Internal
Close
();
this
->
listener
->
OnTcpConnectionClosed
(
this
);
}
void
TcpConnectionHandle
::
InternalClose
()
{
MS_TRACE
();
if
(
this
->
closed
)
{
return
;
}
int
err
;
this
->
closed
=
true
;
// Tell the UV handle that the TcpConnectionHandle has been closed.
this
->
uvHandle
->
data
=
nullptr
;
// Don't read more.
err
=
uv_read_stop
(
reinterpret_cast
<
uv_stream_t
*>
(
this
->
uvHandle
));
if
(
err
!=
0
)
{
MS_ABORT
(
"uv_read_stop() failed: %s"
,
uv_strerror
(
err
));
}
// If there is no error and the peer didn't close its connection side then close gracefully.
if
(
!
this
->
hasError
&&
!
this
->
isClosedByPeer
)
{
// Use uv_shutdown() so pending data to be written will be sent to the peer
// before closing.
auto
*
req
=
new
uv_shutdown_t
;
req
->
data
=
static_cast
<
void
*>
(
this
);
err
=
uv_shutdown
(
req
,
reinterpret_cast
<
uv_stream_t
*>
(
this
->
uvHandle
),
static_cast
<
uv_shutdown_cb
>
(
onShutdown
));
if
(
err
!=
0
)
{
MS_ABORT
(
"uv_shutdown() failed: %s"
,
uv_strerror
(
err
));
}
}
// Otherwise directly close the socket.
else
{
uv_close
(
reinterpret_cast
<
uv_handle_t
*>
(
this
->
uvHandle
),
static_cast
<
uv_close_cb
>
(
onCloseTcp
));
}
}
bool
TcpConnectionHandle
::
SetPeerAddress
()
{
MS_TRACE
();
...
...
@@ -450,7 +464,7 @@ inline void TcpConnectionHandle::OnUvRead(ssize_t nread, const uv_buf_t* /*buf*/
this
->
isClosedByPeer
=
true
;
// Close server side of the connection.
Close
();
Internal
Close
();
// Notify the listener.
this
->
listener
->
OnTcpConnectionClosed
(
this
);
...
...
@@ -463,7 +477,7 @@ inline void TcpConnectionHandle::OnUvRead(ssize_t nread, const uv_buf_t* /*buf*/
this
->
hasError
=
true
;
// Close server side of the connection.
Close
();
Internal
Close
();
// Notify the listener.
this
->
listener
->
OnTcpConnectionClosed
(
this
);
...
...
@@ -497,7 +511,7 @@ inline void TcpConnectionHandle::OnUvWrite(int status, TcpConnectionHandle::onSe
(
*
cb
)(
false
);
}
Close
();
Internal
Close
();
this
->
listener
->
OnTcpConnectionClosed
(
this
);
}
...
...
worker/src/handles/TcpServerHandle.cpp
浏览文件 @
34336429
...
...
@@ -65,34 +65,10 @@ TcpServerHandle::~TcpServerHandle()
if
(
!
this
->
closed
)
{
Close
();
Internal
Close
();
}
}
void
TcpServerHandle
::
Close
()
{
MS_TRACE
();
if
(
this
->
closed
)
{
return
;
}
this
->
closed
=
true
;
// Tell the UV handle that the TcpServerHandle has been closed.
this
->
uvHandle
->
data
=
nullptr
;
MS_DEBUG_DEV
(
"closing %zu active connections"
,
this
->
connections
.
size
());
for
(
auto
*
connection
:
this
->
connections
)
{
delete
connection
;
}
uv_close
(
reinterpret_cast
<
uv_handle_t
*>
(
this
->
uvHandle
),
static_cast
<
uv_close_cb
>
(
onCloseTcp
));
}
void
TcpServerHandle
::
Dump
()
const
{
MS_DUMP
(
"<TcpServerHandle>"
);
...
...
@@ -219,6 +195,30 @@ void TcpServerHandle::AcceptTcpConnection(TcpConnectionHandle* connection)
this
->
connections
.
insert
(
connection
);
}
void
TcpServerHandle
::
InternalClose
()
{
MS_TRACE
();
if
(
this
->
closed
)
{
return
;
}
this
->
closed
=
true
;
// Tell the UV handle that the TcpServerHandle has been closed.
this
->
uvHandle
->
data
=
nullptr
;
MS_DEBUG_DEV
(
"closing %zu active connections"
,
this
->
connections
.
size
());
for
(
auto
*
connection
:
this
->
connections
)
{
delete
connection
;
}
uv_close
(
reinterpret_cast
<
uv_handle_t
*>
(
this
->
uvHandle
),
static_cast
<
uv_close_cb
>
(
onCloseTcp
));
}
bool
TcpServerHandle
::
SetLocalAddress
()
{
MS_TRACE
();
...
...
worker/src/handles/TimerHandle.cpp
浏览文件 @
34336429
...
...
@@ -43,24 +43,10 @@ TimerHandle::~TimerHandle()
if
(
!
this
->
closed
)
{
Close
();
Internal
Close
();
}
}
void
TimerHandle
::
Close
()
{
MS_TRACE
();
if
(
this
->
closed
)
{
return
;
}
this
->
closed
=
true
;
uv_close
(
reinterpret_cast
<
uv_handle_t
*>
(
this
->
uvHandle
),
static_cast
<
uv_close_cb
>
(
onCloseTimer
));
}
void
TimerHandle
::
Start
(
uint64_t
timeout
,
uint64_t
repeat
)
{
MS_TRACE
();
...
...
@@ -154,6 +140,20 @@ void TimerHandle::Restart()
}
}
void
TimerHandle
::
InternalClose
()
{
MS_TRACE
();
if
(
this
->
closed
)
{
return
;
}
this
->
closed
=
true
;
uv_close
(
reinterpret_cast
<
uv_handle_t
*>
(
this
->
uvHandle
),
static_cast
<
uv_close_cb
>
(
onCloseTimer
));
}
inline
void
TimerHandle
::
OnUvTimer
()
{
MS_TRACE
();
...
...
worker/src/handles/UdpSocketHandle.cpp
浏览文件 @
34336429
...
...
@@ -103,35 +103,10 @@ UdpSocketHandle::~UdpSocketHandle()
if
(
!
this
->
closed
)
{
Close
();
Internal
Close
();
}
}
void
UdpSocketHandle
::
Close
()
{
MS_TRACE
();
if
(
this
->
closed
)
{
return
;
}
this
->
closed
=
true
;
// Tell the UV handle that the UdpSocketHandle has been closed.
this
->
uvHandle
->
data
=
nullptr
;
// Don't read more.
const
int
err
=
uv_udp_recv_stop
(
this
->
uvHandle
);
if
(
err
!=
0
)
{
MS_ABORT
(
"uv_udp_recv_stop() failed: %s"
,
uv_strerror
(
err
));
}
uv_close
(
reinterpret_cast
<
uv_handle_t
*>
(
this
->
uvHandle
),
static_cast
<
uv_close_cb
>
(
onCloseUdp
));
}
void
UdpSocketHandle
::
Dump
()
const
{
MS_DUMP
(
"<UdpSocketHandle>"
);
...
...
@@ -338,6 +313,31 @@ void UdpSocketHandle::SetRecvBufferSize(uint32_t size)
}
}
void
UdpSocketHandle
::
InternalClose
()
{
MS_TRACE
();
if
(
this
->
closed
)
{
return
;
}
this
->
closed
=
true
;
// Tell the UV handle that the UdpSocketHandle has been closed.
this
->
uvHandle
->
data
=
nullptr
;
// Don't read more.
const
int
err
=
uv_udp_recv_stop
(
this
->
uvHandle
);
if
(
err
!=
0
)
{
MS_ABORT
(
"uv_udp_recv_stop() failed: %s"
,
uv_strerror
(
err
));
}
uv_close
(
reinterpret_cast
<
uv_handle_t
*>
(
this
->
uvHandle
),
static_cast
<
uv_close_cb
>
(
onCloseUdp
));
}
bool
UdpSocketHandle
::
SetLocalAddress
()
{
MS_TRACE
();
...
...
worker/src/handles/UnixStreamSocketHandle.cpp
浏览文件 @
34336429
...
...
@@ -126,14 +126,16 @@ UnixStreamSocketHandle::~UnixStreamSocketHandle()
{
MS_TRACE_STD
();
delete
[]
this
->
buffer
;
if
(
!
this
->
closed
)
{
Close
();
}
delete
[]
this
->
buffer
;
}
// NOTE: In UnixStreamSocketHandle we need a poublic Close() method and cannot
// just rely on the destructor plus a private InternalClose() method.
void
UnixStreamSocketHandle
::
Close
()
{
MS_TRACE_STD
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论