node-webrtc
node-webrtc copied to clipboard
wrtc crashed after RTCPeerConnection.close() being called.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `/home/yhu/workspace/xxxxx/node_modules/electron/dist/electron --inspect=5858 /'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00007f0811b56f49 in node_webrtc::RTCDataChannel::CleanupInternals() () from /home/yhu/workspace/xxxxxx/node_modules/wrtc/build/Release/wrtc.node
[Current thread is 1 (Thread 0x7f0829ba0b40 (LWP 26624))]
(gdb) bt
#0 0x00007f0811b56f49 in node_webrtc::RTCDataChannel::CleanupInternals() () from /home/yhu/workspace/xxxxx/node_modules/wrtc/build/Release/wrtc.node
#1 0x00007f0811b5b8e8 in node_webrtc::RTCDataChannel::OnPeerConnectionClosed() () from /home/yhu/workspace/xxxxx/node_modules/wrtc/build/Release/wrtc.node
#2 0x00007f0811b7c1ec in node_webrtc::RTCPeerConnection::Close(Napi::CallbackInfo const&) () from /home/yhu/workspace/xxxxx/node_modules/wrtc/build/Release/wrtc.node
#3 0x00007f0811b8828d in Napi::ObjectWrap<node_webrtc::RTCPeerConnection>::InstanceMethodCallbackWrapper(napi_env__*, napi_callback_info__*) ()
from /home/yhu/workspace/xxxxx/node_modules/wrtc/build/Release/wrtc.node
#4 0x00005578c04e8041 in ?? ()
#5 0x00005578c09df3a0 in ?? ()
#6 0x00007ffec6f0db20 in ?? ()
#7 0x0000000000000000 in ?? ()
(gdb)
Just a guess, it might be a reentrant issue. We might need to add a lock when we are doing cleanup for the same instance.
void RTCDataChannel::CleanupInternals() {
if (_jingleDataChannel == nullptr) {
return;
}
_jingleDataChannel->UnregisterObserver();
_cached_id = _jingleDataChannel->id();
_cached_label = _jingleDataChannel->label();
_cached_max_packet_life_time = _jingleDataChannel->maxRetransmitTime();
_cached_max_retransmits = _jingleDataChannel->maxRetransmits();
_cached_negotiated = _jingleDataChannel->negotiated();
_cached_ordered = _jingleDataChannel->ordered();
_cached_protocol = _jingleDataChannel->protocol();
_cached_buffered_amount = _jingleDataChannel->buffered_amount();
_jingleDataChannel = nullptr;
}
|0x7fba9ca79f43 <_ZN11node_webrtc14RTCDataChannel16CleanupInternalsEv+35> je 0x7fba9ca7a09b <_ZN11node_webrtc14RTCDataChannel16CleanupInternalsEv+379> |
|0x7fba9ca79f49 <_ZN11node_webrtc14RTCDataChannel16CleanupInternalsEv+41> mov (%rdi),%rax |
|0x7fba9ca79f4c <_ZN11node_webrtc14RTCDataChannel16CleanupInternalsEv+44> mov %rsp,%rbp |
>|0x7fba9ca79f4f <_ZN11node_webrtc14RTCDataChannel16CleanupInternalsEv+47> callq *0x28(%rax)
(gdb) p/x $rax
$1 = 0xffffccafb2aaef05
obviously, the address saved in rax is invalid. which means _jingleDataChannel is invalid value. And it's not a null pointer. That why it crashed.
SHOULD we set _jingleDataChannel = nullptr after close()?
Napi::Value RTCDataChannel::Close(const Napi::CallbackInfo& info) {
if (_jingleDataChannel != nullptr) {
_jingleDataChannel->Close();//SHOULD we set _jingleDataChannel = nullptr after close()?
}
return info.Env().Undefined();
}
Looked like they are same issue: https://github.com/node-webrtc/node-webrtc/issues/458
And try/catch fix won't work for segmentation fault. We might need to find another way to solve the issue.