yocontra / rtc-everywhere

Cross-everything WebRTC mega-project
http://rtc.works
MIT License
651 stars 40 forks source link

Segmentation fault during execution #14

Closed GeneGenie closed 6 years ago

GeneGenie commented 7 years ago

Hello guys, i'm facing an issue

PID 91386 received SIGSEGV for address: 0x0 0 segfault-handler.node 0x0000000101fd3218 _ZL16segfault_handleriP9__siginfoPv + 280 1 libsystem_platform.dylib 0x00007fff965d952a _sigtramp + 26 2 ??? 0x0000000000000007 0x0 + 7 3 wrtc.node 0x0000000107002d01 _ZN3Nan3impL23FunctionCallbackWrapperERKN2v820FunctionCallbackInfoINS1_5ValueEEE + 131 4 node 0x0000000100182e54 _ZN2v88internal25FunctionCallbackArguments4CallEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEE + 356 5 node 0x00000001001cce5d _ZN2v88internal12_GLOBAL__N_119HandleApiCallHelperILb0EEENS0_11MaybeHandleINS0_6ObjectEEEPNS0_7IsolateENS1_16BuiltinArgumentsILNS0_21BuiltinExtraArgumentsE1EEE + 1069 6 node 0x00000001001d74b1 _ZN2v88internalL21Builtin_HandleApiCallEiPPNS0_6ObjectEPNS0_7IsolateE + 465 7 ??? 0x0000010095d092a7 0x0 + 1102025101991 8 ??? 0x00000100960c50ca 0x0 + 1102029017290

Application is setting P2P data channel connection with browser. Where browser is always initiator.


var http = require('http').Server(app);
var io = require('socket.io')(http);
var url = require('url');
var rtc = require('rtc-everywhere')();
var stunConfig = null
var P2P = rtc.RTCPeerConnection
function startRtcConnection() {
    var pc = new P2P(stunConfig);
    pc.ondatachannel = function (evt) {
        try {
            var channel = evt.channel;
            channel.onclose = function () {
                console.log("RTC DATA CHANNEL CLOSE")
            }
            channel.onerror = function (e) {
                console.error("RTC DATA CHANNEL ERROR", e)
            }
            channel.onopen = function () {
                console.log("CHANNEL READY")
            };
            channel.onmessage = function (evt) {
                try {
                    if (!evt.data) return;
                   //logic 
                } catch (e) {
                    logError(e)
                }
            };
        } catch (e) {
            logError(e)
        }
    };
    return pc
}
var SegfaultHandler = require('segfault-handler');
SegfaultHandler.registerHandler("crash.log", function (signal, address, stack) {
    console.log("crash", signal, stack)
});
io.on('connection', function (socket) {
    var pc = startRtcConnection()
    socket.on('ice', function (msg) {
            var message = JSON.parse(msg)
            if (message.desc) {
                var desc = message.desc;
                if (desc.type == "offer") {
                    pc.setRemoteDescription(desc).then(function () {
                        return pc.createAnswer();
                    })
                        .then(function (answer) {
                            return pc.setLocalDescription(answer);
                        })
                        .then(function () {
                            var str = JSON.stringify({"desc": pc.localDescription});
                            socket.emit("ice", str);
                        })
                        .catch(logError);
                }
            }
            if (!!message.candidate)
                pc.addIceCandidate(message.candidate).catch(logError);
    });
});
function logError(e) {
    console.error("ERROR", e)
}
http.listen(3000);

Am I doing something wrong?
yocontra commented 7 years ago

What version of node are you using?

yocontra commented 7 years ago

We use this under the hood for node support so you should probably check here: https://github.com/js-platform/node-webrtc

GeneGenie commented 7 years ago

This is node v6.5.0 OSx 10.11.5

GeneGenie commented 7 years ago

The issue reproduces even if I'll remove all the logical parts and leave only peer creation on socket connection. After 4-10 requests it fails.

Well the basic question was am I doing something wrong from the logical point of view, I'm new to wrtc. Basic idea is: make separate wrtc connections (P2P client<->server) with each socket client

yocontra commented 7 years ago

@GeneGenie Do you see anything on the node-webrtc issues thats similar to yours? I'm thinking it doesn't work w/ your node version. You should try opening a ticket there.

yocontra commented 6 years ago

Closing, no response. Let me know if this is still an issue and I will reopen.