ossrs / srs

SRS is a simple, high-efficiency, real-time media server supporting RTMP, WebRTC, HLS, HTTP-FLV, HTTP-TS, SRT, MPEG-DASH, and GB28181.
https://ossrs.io
MIT License
25.69k stars 5.38k forks source link

RTC: Call on_play before create session, for it might be freed for timeout. #3455

Closed xiaozhihong closed 1 year ago

xiaozhihong commented 1 year ago

When callback the on_play, it might be blocked and context will be switched to other coroutine, then the created session might be freed for timeout. After the callback is done, the destroied session will be used and cause the crash.

I changed the order to call on_play before create session, in order to avoid destroying the session object. However, the best solution is use shared ptr, and we're developing it.

xiaozhihong commented 1 year ago

https://github.com/ossrs/srs/commit/6a108fab6d#diff-2d94fb08a8b76aa40f71a392bb00afc19bb96767bd874cf74582a011488dc88cR207

Here is a comment written, stating that there is a sequential dependency, but from the code, there doesn't seem to be any dependency.

TRANS_BY_GPT3

winlinvip commented 1 year ago

6a108fab6d#diff-2d94fb08a8b76aa40f71a392bb00afc19bb96767bd874cf74582a011488dc88cR207

Here is a comment stating that there is a sequential dependency, but from the code it doesn't seem to have any dependency.

'on_play' depends on the object created by 'stat', but it shouldn't have any dependency here. There must be dependencies in other places.

This comment is mainly a reminder that calling it before 'stat' will result in the client id not being found.

TRANS_BY_GPT3

limjoe commented 1 year ago

@xiaozhihong I haven't enabled webrtc protocol distribution on my side, only http-flv and rtmp live protocol distribution are enabled, but it still reports the crash mentioned in #3413.

TRANS_BY_GPT3