提交 f1b8d026 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

2.6.18

上级 a4bbbce0
# Changelog # Changelog
### 2.6.18
* Fix usage of a deallocated `RTC::TcpConnection` instance under heavy CPU usage due to mediasoup deleting the instance in the middle of a receiving iteration.
### 2.6.17 ### 2.6.17
* Improve build system by using all available CPU cores in parallel. * Improve build system by using all available CPU cores in parallel.
......
{ {
"name": "mediasoup", "name": "mediasoup",
"version": "2.6.17", "version": "2.6.18",
"description": "Cutting Edge WebRTC Video Conferencing", "description": "Cutting Edge WebRTC Video Conferencing",
"author": "Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)", "author": "Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)",
"contributors": [ "contributors": [
......
...@@ -214,22 +214,15 @@ void TcpConnection::Write(const uint8_t* data, size_t len) ...@@ -214,22 +214,15 @@ void TcpConnection::Write(const uint8_t* data, size_t len)
// Set written to 0 so pendingLen can be properly calculated. // Set written to 0 so pendingLen can be properly calculated.
written = 0; written = 0;
} }
// Error. Should not happen. // Another error.
else if (written < 0) else if (written < 0)
{ {
MS_WARN_DEV("uv_try_write() failed, closing the connection: %s", uv_strerror(written)); MS_WARN_DEV("uv_try_write() failed: %s", uv_strerror(written));
Close(); // Set written to 0 so pendingLen can be properly calculated.
written = 0;
this->listener->OnTcpConnectionClosed(this);
return;
} }
// MS_DEBUG_DEV(
// "could just write %zu bytes (%zu given) at first time, using uv_write() now",
// static_cast<size_t>(written), len);
size_t pendingLen = len - written; size_t pendingLen = len - written;
// Allocate a special UvWriteData struct pointer. // Allocate a special UvWriteData struct pointer.
auto* writeData = static_cast<UvWriteData*>(std::malloc(sizeof(UvWriteData) + pendingLen)); auto* writeData = static_cast<UvWriteData*>(std::malloc(sizeof(UvWriteData) + pendingLen));
...@@ -282,22 +275,15 @@ void TcpConnection::Write(const uint8_t* data1, size_t len1, const uint8_t* data ...@@ -282,22 +275,15 @@ void TcpConnection::Write(const uint8_t* data1, size_t len1, const uint8_t* data
// Set written to 0 so pendingLen can be properly calculated. // Set written to 0 so pendingLen can be properly calculated.
written = 0; written = 0;
} }
// Error. Should not happen. // Another error.
else if (written < 0) else if (written < 0)
{ {
MS_WARN_DEV("uv_try_write() failed, closing the connection: %s", uv_strerror(written)); MS_WARN_DEV("uv_try_write() failed: %s", uv_strerror(written));
Close(); // Set written to 0 so pendingLen can be properly calculated.
written = 0;
this->listener->OnTcpConnectionClosed(this);
return;
} }
// MS_DEBUG_DEV(
// "could just write %zu bytes (%zu given) at first time, using uv_write() now",
// static_cast<size_t>(written), totalLen);
size_t pendingLen = totalLen - written; size_t pendingLen = totalLen - written;
// Allocate a special UvWriteData struct pointer. // Allocate a special UvWriteData struct pointer.
......
...@@ -233,7 +233,7 @@ void UdpSocket::Send(const uint8_t* data, size_t len, const struct sockaddr* add ...@@ -233,7 +233,7 @@ void UdpSocket::Send(const uint8_t* data, size_t len, const struct sockaddr* add
return; return;
} }
if (sent >= 0) else if (sent >= 0)
{ {
MS_WARN_DEV("datagram truncated (just %d of %zu bytes were sent)", sent, len); MS_WARN_DEV("datagram truncated (just %d of %zu bytes were sent)", sent, len);
...@@ -242,16 +242,11 @@ void UdpSocket::Send(const uint8_t* data, size_t len, const struct sockaddr* add ...@@ -242,16 +242,11 @@ void UdpSocket::Send(const uint8_t* data, size_t len, const struct sockaddr* add
return; return;
} }
// Error, // Any error but legit EAGAIN. Use uv_udp_send().
if (sent != UV_EAGAIN) else if (sent != UV_EAGAIN)
{ {
MS_WARN_DEV("uv_udp_try_send() failed: %s", uv_strerror(sent)); MS_WARN_DEV("uv_udp_try_send() failed: %s", uv_strerror(sent));
return;
} }
// Otherwise UV_EAGAIN was returned so cannot send data at first time. Use uv_udp_send().
// MS_DEBUG_DEV("could not send the datagram at first time, using uv_udp_send() now");
// Allocate a special UvSendData struct pointer. // Allocate a special UvSendData struct pointer.
auto* sendData = static_cast<UvSendData*>(std::malloc(sizeof(UvSendData) + len)); auto* sendData = static_cast<UvSendData*>(std::malloc(sizeof(UvSendData) + len));
......
...@@ -159,6 +159,8 @@ void UnixStreamSocket::Close() ...@@ -159,6 +159,8 @@ void UnixStreamSocket::Close()
void UnixStreamSocket::Write(const uint8_t* data, size_t len) void UnixStreamSocket::Write(const uint8_t* data, size_t len)
{ {
MS_TRACE_STD();
if (this->closed) if (this->closed)
return; return;
...@@ -186,17 +188,13 @@ void UnixStreamSocket::Write(const uint8_t* data, size_t len) ...@@ -186,17 +188,13 @@ void UnixStreamSocket::Write(const uint8_t* data, size_t len)
// Set written to 0 so pendingLen can be properly calculated. // Set written to 0 so pendingLen can be properly calculated.
written = 0; written = 0;
} }
// Error. Should not happen. // Another error.
else if (written < 0) else if (written < 0)
{ {
MS_ERROR_STD("uv_try_write() failed, closing the socket: %s", uv_strerror(written)); MS_ERROR_STD("uv_try_write() failed: %s", uv_strerror(written));
Close();
// Notify the subclass.
UserOnUnixStreamSocketClosed(this->isClosedByPeer);
return; // Set written to 0 so pendingLen can be properly calculated.
written = 0;
} }
size_t pendingLen = len - written; size_t pendingLen = len - written;
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论