drachtio-srf icon indicating copy to clipboard operation
drachtio-srf copied to clipboard

Incorrect socket selected in outbound mode

Open jonastelzio opened this issue 3 years ago • 2 comments

When running SRF in outbound connection mode, in functions like 'createB2BUA', the default socket selected is basically 'the first socket' it can find. The code workaround to this is forwarding the _socket parameter like this:

srf.createB2BUA(req, res, destSipUri, {
    headers: forwardHeaders,
    passFailure: false,
    localSdpB: rtpOffer.sdp,
    localSdpA: async (remoteSdp, res) => await this.getSdpAnswer(remoteSdp, res),
    _socket: req.socket  // <- pass on the incoming req.socket here
})

This workaround works, but it's interacting with a _prefixed parameter, and is completely undocumented. If I don't set the _socket parameter, SRF will automatically just pick the first socket in the sockets collection, which can (and will in most cases), belong to a completely unrelated SRF session.

jonastelzio avatar Oct 20 '21 10:10 jonastelzio

Good point, would you agree that Srf.createB2BUA should set _socket for you? If so I can make that change

davehorton avatar Oct 20 '21 12:10 davehorton

@davehorton Yeah, I think it would make sense that it picks whatever socket is associated with the passed in Request? I can't really think of a use case for ever having it belong to another connection, at least in outbound mode. In "inbound mode" it could make sense I suppose, maybe?

jonastelzio avatar Oct 20 '21 17:10 jonastelzio