Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
f5eec143
Unverified
提交
f5eec143
authored
3月 27, 2022
作者:
Nazar Mokrynskyi
提交者:
GitHub
3月 27, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #800 from nazar-pc/fix-rust-test-segfault
Fix rust test segfault
上级
ce3f5f98
a5b52560
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
68 行增加
和
28 行删除
+68
-28
worker.rs
rust/src/worker.rs
+24
-16
channel.rs
rust/src/worker/channel.rs
+23
-5
payload_channel.rs
rust/src/worker/payload_channel.rs
+16
-5
utils.rs
rust/src/worker/utils.rs
+5
-2
没有找到文件。
rust/src/worker.rs
浏览文件 @
f5eec143
...
@@ -345,15 +345,23 @@ impl Inner {
...
@@ -345,15 +345,23 @@ impl Inner {
spawn_args
.join
(
" "
)
spawn_args
.join
(
" "
)
);
);
let
closed
=
Arc
::
new
(
AtomicBool
::
new
(
false
));
let
(
mut
status_sender
,
status_receiver
)
=
async_oneshot
::
oneshot
();
let
(
mut
status_sender
,
status_receiver
)
=
async_oneshot
::
oneshot
();
let
WorkerRunResult
{
let
WorkerRunResult
{
channel
,
channel
,
payload_channel
,
payload_channel
,
buffer_worker_messages_guard
,
buffer_worker_messages_guard
,
}
=
utils
::
run_worker_with_channels
(
id
,
thread_initializer
,
spawn_args
,
move
|
result
|
{
}
=
utils
::
run_worker_with_channels
(
let
_
=
status_sender
.send
(
result
);
id
,
on_exit
();
thread_initializer
,
});
spawn_args
,
Arc
::
clone
(
&
closed
),
move
|
result
|
{
let
_
=
status_sender
.send
(
result
);
on_exit
();
},
);
let
handlers
=
Handlers
::
default
();
let
handlers
=
Handlers
::
default
();
...
@@ -364,7 +372,7 @@ impl Inner {
...
@@ -364,7 +372,7 @@ impl Inner {
executor
,
executor
,
handlers
,
handlers
,
app_data
,
app_data
,
closed
:
Arc
::
new
(
AtomicBool
::
new
(
false
))
,
closed
,
_worker_manager
:
worker_manager
,
_worker_manager
:
worker_manager
,
};
};
...
@@ -502,20 +510,20 @@ impl Inner {
...
@@ -502,20 +510,20 @@ impl Inner {
fn
close
(
&
self
)
{
fn
close
(
&
self
)
{
let
already_closed
=
self
.closed
.swap
(
true
,
Ordering
::
SeqCst
);
let
already_closed
=
self
.closed
.swap
(
true
,
Ordering
::
SeqCst
);
let
channel
=
self
.channel
.clone
();
if
!
already_closed
{
let
payload_channel
=
self
.payload_channel
.clone
();
let
channel
=
self
.channel
.clone
();
let
payload_channel
=
self
.payload_channel
.clone
();
self
.executor
self
.executor
.spawn
(
async
move
{
.spawn
(
async
move
{
let
_
=
channel
.request
(
WorkerCloseRequest
{})
.await
;
let
_
=
channel
.request
(
WorkerCloseRequest
{})
.await
;
// Drop channels in here after response from worker
// Drop channels in here after response from worker
drop
(
channel
);
drop
(
channel
);
drop
(
payload_channel
);
drop
(
payload_channel
);
})
})
.detach
();
.detach
();
if
!
already_closed
{
self
.handlers.close
.call_simple
();
self
.handlers.close
.call_simple
();
}
}
}
}
...
...
rust/src/worker/channel.rs
浏览文件 @
f5eec143
use
crate
::
messages
::
Request
;
use
crate
::
messages
::
{
Request
,
WorkerCloseRequest
}
;
use
crate
::
worker
::
common
::{
EventHandlers
,
SubscriptionTarget
,
WeakEventHandlers
};
use
crate
::
worker
::
common
::{
EventHandlers
,
SubscriptionTarget
,
WeakEventHandlers
};
use
crate
::
worker
::
utils
;
use
crate
::
worker
::
utils
;
use
crate
::
worker
::
utils
::{
PreparedChannelRead
,
PreparedChannelWrite
};
use
crate
::
worker
::
utils
::{
PreparedChannelRead
,
PreparedChannelWrite
};
...
@@ -11,8 +11,10 @@ use mediasoup_sys::UvAsyncT;
...
@@ -11,8 +11,10 @@ use mediasoup_sys::UvAsyncT;
use
parking_lot
::
Mutex
;
use
parking_lot
::
Mutex
;
use
serde
::{
Deserialize
,
Serialize
};
use
serde
::{
Deserialize
,
Serialize
};
use
serde_json
::
Value
;
use
serde_json
::
Value
;
use
std
::
any
::
TypeId
;
use
std
::
collections
::
VecDeque
;
use
std
::
collections
::
VecDeque
;
use
std
::
fmt
::
Debug
;
use
std
::
fmt
::
Debug
;
use
std
::
sync
::
atomic
::{
AtomicBool
,
Ordering
};
use
std
::
sync
::{
Arc
,
Weak
};
use
std
::
sync
::{
Arc
,
Weak
};
#[derive(Debug,
Deserialize)]
#[derive(Debug,
Deserialize)]
...
@@ -162,6 +164,8 @@ struct Inner {
...
@@ -162,6 +164,8 @@ struct Inner {
requests_container_weak
:
Weak
<
Mutex
<
RequestsContainer
>>
,
requests_container_weak
:
Weak
<
Mutex
<
RequestsContainer
>>
,
buffered_notifications_for
:
Arc
<
Mutex
<
HashedMap
<
SubscriptionTarget
,
Vec
<
Vec
<
u8
>>>>>
,
buffered_notifications_for
:
Arc
<
Mutex
<
HashedMap
<
SubscriptionTarget
,
Vec
<
Vec
<
u8
>>>>>
,
event_handlers_weak
:
WeakEventHandlers
<
Arc
<
dyn
Fn
(
&
[
u8
])
+
Send
+
Sync
+
'static
>>
,
event_handlers_weak
:
WeakEventHandlers
<
Arc
<
dyn
Fn
(
&
[
u8
])
+
Send
+
Sync
+
'static
>>
,
worker_closed
:
Arc
<
AtomicBool
>
,
closed
:
AtomicBool
,
}
}
impl
Drop
for
Inner
{
impl
Drop
for
Inner
{
...
@@ -176,7 +180,9 @@ pub(crate) struct Channel {
...
@@ -176,7 +180,9 @@ pub(crate) struct Channel {
}
}
impl
Channel
{
impl
Channel
{
pub
(
super
)
fn
new
()
->
(
Self
,
PreparedChannelRead
,
PreparedChannelWrite
)
{
pub
(
super
)
fn
new
(
worker_closed
:
Arc
<
AtomicBool
>
,
)
->
(
Self
,
PreparedChannelRead
,
PreparedChannelWrite
)
{
let
outgoing_message_buffer
=
Arc
::
new
(
Mutex
::
new
(
OutgoingMessageBuffer
{
let
outgoing_message_buffer
=
Arc
::
new
(
Mutex
::
new
(
OutgoingMessageBuffer
{
handle
:
None
,
handle
:
None
,
messages
:
VecDeque
::
with_capacity
(
10
),
messages
:
VecDeque
::
with_capacity
(
10
),
...
@@ -270,6 +276,8 @@ impl Channel {
...
@@ -270,6 +276,8 @@ impl Channel {
requests_container_weak
,
requests_container_weak
,
buffered_notifications_for
,
buffered_notifications_for
,
event_handlers_weak
,
event_handlers_weak
,
worker_closed
,
closed
:
AtomicBool
::
new
(
false
),
});
});
(
(
...
@@ -301,7 +309,7 @@ impl Channel {
...
@@ -301,7 +309,7 @@ impl Channel {
pub
(
crate
)
async
fn
request
<
R
>
(
&
self
,
request
:
R
)
->
Result
<
R
::
Response
,
RequestError
>
pub
(
crate
)
async
fn
request
<
R
>
(
&
self
,
request
:
R
)
->
Result
<
R
::
Response
,
RequestError
>
where
where
R
:
Request
,
R
:
Request
+
'static
,
{
{
let
method
=
request
.as_method
();
let
method
=
request
.as_method
();
...
@@ -338,10 +346,20 @@ impl Channel {
...
@@ -338,10 +346,20 @@ impl Channel {
outgoing_message_buffer
outgoing_message_buffer
.messages
.messages
.push_back
(
Arc
::
clone
(
&
message
));
.push_back
(
Arc
::
clone
(
&
message
));
if
let
Some
(
handle
)
=
&
outgoing_message_buffer
.handle
{
if
let
Some
(
handle
)
=
outgoing_message_buffer
.handle
{
if
self
.inner.worker_closed
.load
(
Ordering
::
Acquire
)
{
// Forbid all requests after worker closing except one worker closing request
let
first_worker_closing
=
TypeId
::
of
::
<
R
>
()
==
TypeId
::
of
::
<
WorkerCloseRequest
>
()
&&
!
self
.inner.closed
.swap
(
true
,
Ordering
::
Relaxed
);
if
!
first_worker_closing
{
return
Err
(
RequestError
::
ChannelClosed
);
}
}
unsafe
{
unsafe
{
// Notify worker that there is something to read
// Notify worker that there is something to read
let
ret
=
mediasoup_sys
::
uv_async_send
(
*
handle
);
let
ret
=
mediasoup_sys
::
uv_async_send
(
handle
);
if
ret
!=
0
{
if
ret
!=
0
{
error!
(
"uv_async_send call failed with code {}"
,
ret
);
error!
(
"uv_async_send call failed with code {}"
,
ret
);
return
Err
(
RequestError
::
ChannelClosed
);
return
Err
(
RequestError
::
ChannelClosed
);
...
...
rust/src/worker/payload_channel.rs
浏览文件 @
f5eec143
...
@@ -11,6 +11,7 @@ use serde::{Deserialize, Serialize};
...
@@ -11,6 +11,7 @@ use serde::{Deserialize, Serialize};
use
serde_json
::
Value
;
use
serde_json
::
Value
;
use
std
::
collections
::
VecDeque
;
use
std
::
collections
::
VecDeque
;
use
std
::
fmt
::
Debug
;
use
std
::
fmt
::
Debug
;
use
std
::
sync
::
atomic
::{
AtomicBool
,
Ordering
};
use
std
::
sync
::{
Arc
,
Weak
};
use
std
::
sync
::{
Arc
,
Weak
};
use
thiserror
::
Error
;
use
thiserror
::
Error
;
...
@@ -139,6 +140,7 @@ struct Inner {
...
@@ -139,6 +140,7 @@ struct Inner {
requests_container_weak
:
Weak
<
Mutex
<
RequestsContainer
>>
,
requests_container_weak
:
Weak
<
Mutex
<
RequestsContainer
>>
,
#[allow(clippy
::
type_complexity)]
#[allow(clippy
::
type_complexity)]
event_handlers_weak
:
WeakEventHandlers
<
Arc
<
dyn
Fn
(
&
[
u8
],
&
[
u8
])
+
Send
+
Sync
+
'static
>>
,
event_handlers_weak
:
WeakEventHandlers
<
Arc
<
dyn
Fn
(
&
[
u8
],
&
[
u8
])
+
Send
+
Sync
+
'static
>>
,
worker_closed
:
Arc
<
AtomicBool
>
,
}
}
impl
Drop
for
Inner
{
impl
Drop
for
Inner
{
...
@@ -153,7 +155,9 @@ pub(crate) struct PayloadChannel {
...
@@ -153,7 +155,9 @@ pub(crate) struct PayloadChannel {
}
}
impl
PayloadChannel
{
impl
PayloadChannel
{
pub
(
super
)
fn
new
()
->
(
pub
(
super
)
fn
new
(
worker_closed
:
Arc
<
AtomicBool
>
,
)
->
(
Self
,
Self
,
PreparedPayloadChannelRead
,
PreparedPayloadChannelRead
,
PreparedPayloadChannelWrite
,
PreparedPayloadChannelWrite
,
...
@@ -241,6 +245,7 @@ impl PayloadChannel {
...
@@ -241,6 +245,7 @@ impl PayloadChannel {
internal_message_receiver
,
internal_message_receiver
,
requests_container_weak
,
requests_container_weak
,
event_handlers_weak
,
event_handlers_weak
,
worker_closed
,
});
});
(
(
...
@@ -298,10 +303,13 @@ impl PayloadChannel {
...
@@ -298,10 +303,13 @@ impl PayloadChannel {
outgoing_message_buffer
outgoing_message_buffer
.messages
.messages
.push_back
(
OutgoingMessage
::
Request
(
Arc
::
clone
(
&
message_with_payload
)));
.push_back
(
OutgoingMessage
::
Request
(
Arc
::
clone
(
&
message_with_payload
)));
if
let
Some
(
handle
)
=
&
outgoing_message_buffer
.handle
{
if
let
Some
(
handle
)
=
outgoing_message_buffer
.handle
{
if
self
.inner.worker_closed
.load
(
Ordering
::
Acquire
)
{
return
Err
(
RequestError
::
ChannelClosed
);
}
unsafe
{
unsafe
{
// Notify worker that there is something to read
// Notify worker that there is something to read
let
ret
=
mediasoup_sys
::
uv_async_send
(
*
handle
);
let
ret
=
mediasoup_sys
::
uv_async_send
(
handle
);
if
ret
!=
0
{
if
ret
!=
0
{
error!
(
"uv_async_send call failed with code {}"
,
ret
);
error!
(
"uv_async_send call failed with code {}"
,
ret
);
return
Err
(
RequestError
::
ChannelClosed
);
return
Err
(
RequestError
::
ChannelClosed
);
...
@@ -362,10 +370,13 @@ impl PayloadChannel {
...
@@ -362,10 +370,13 @@ impl PayloadChannel {
outgoing_message_buffer
outgoing_message_buffer
.messages
.messages
.push_back
(
OutgoingMessage
::
Notification
{
message
,
payload
});
.push_back
(
OutgoingMessage
::
Notification
{
message
,
payload
});
if
let
Some
(
handle
)
=
&
outgoing_message_buffer
.handle
{
if
let
Some
(
handle
)
=
outgoing_message_buffer
.handle
{
if
self
.inner.worker_closed
.load
(
Ordering
::
Acquire
)
{
return
Err
(
NotificationError
::
ChannelClosed
);
}
unsafe
{
unsafe
{
// Notify worker that there is something to read
// Notify worker that there is something to read
let
ret
=
mediasoup_sys
::
uv_async_send
(
*
handle
);
let
ret
=
mediasoup_sys
::
uv_async_send
(
handle
);
if
ret
!=
0
{
if
ret
!=
0
{
error!
(
"uv_async_send call failed with code {}"
,
ret
);
error!
(
"uv_async_send call failed with code {}"
,
ret
);
return
Err
(
NotificationError
::
ChannelClosed
);
return
Err
(
NotificationError
::
ChannelClosed
);
...
...
rust/src/worker/utils.rs
浏览文件 @
f5eec143
...
@@ -13,6 +13,7 @@ pub(super) use channel_write_fn::{
...
@@ -13,6 +13,7 @@ pub(super) use channel_write_fn::{
};
};
use
std
::
ffi
::
CString
;
use
std
::
ffi
::
CString
;
use
std
::
os
::
raw
::{
c_char
,
c_int
};
use
std
::
os
::
raw
::{
c_char
,
c_int
};
use
std
::
sync
::
atomic
::
AtomicBool
;
use
std
::
sync
::
Arc
;
use
std
::
sync
::
Arc
;
use
thiserror
::
Error
;
use
thiserror
::
Error
;
...
@@ -46,14 +47,16 @@ pub(super) fn run_worker_with_channels<OE>(
...
@@ -46,14 +47,16 @@ pub(super) fn run_worker_with_channels<OE>(
id
:
WorkerId
,
id
:
WorkerId
,
thread_initializer
:
Option
<
Arc
<
dyn
Fn
()
+
Send
+
Sync
>>
,
thread_initializer
:
Option
<
Arc
<
dyn
Fn
()
+
Send
+
Sync
>>
,
args
:
Vec
<
String
>
,
args
:
Vec
<
String
>
,
worker_closed
:
Arc
<
AtomicBool
>
,
on_exit
:
OE
,
on_exit
:
OE
,
)
->
WorkerRunResult
)
->
WorkerRunResult
where
where
OE
:
FnOnce
(
Result
<
(),
ExitError
>
)
+
Send
+
'static
,
OE
:
FnOnce
(
Result
<
(),
ExitError
>
)
+
Send
+
'static
,
{
{
let
(
channel
,
prepared_channel_read
,
prepared_channel_write
)
=
Channel
::
new
();
let
(
channel
,
prepared_channel_read
,
prepared_channel_write
)
=
Channel
::
new
(
Arc
::
clone
(
&
worker_closed
));
let
(
payload_channel
,
prepared_payload_channel_read
,
prepared_payload_channel_write
)
=
let
(
payload_channel
,
prepared_payload_channel_read
,
prepared_payload_channel_write
)
=
PayloadChannel
::
new
();
PayloadChannel
::
new
(
worker_closed
);
let
buffer_worker_messages_guard
=
channel
.buffer_messages_for
(
std
::
process
::
id
()
.into
());
let
buffer_worker_messages_guard
=
channel
.buffer_messages_for
(
std
::
process
::
id
()
.into
());
std
::
thread
::
Builder
::
new
()
std
::
thread
::
Builder
::
new
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论