-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incidental: Retrieving client through the http interface/api/v1/clients will cause the SRS service to restart. #2311
Comments
Verified, this problem does exist. Reproduction method: Modify the
The problem is very subtle. Due to the optimization of the operating system, the address of 'req' does not change after each 'realloc', making it difficult to reproduce. Only when that block of memory is coincidentally occupied and modified by another program, will it cause a crash.
|
The bug has been fixed, please refer to 497c2d5
|
6689d88 Fix the bug from the previous commit
|
Thank you @duiniuluantanqin for analyzing and identifying the root cause, and providing a PR. Let's summarize this issue. The essence of this issue is that stat directly references req. srs_error_t SrsStatistic::on_client(std::string id, SrsRequest* req, SrsConnection* conn, SrsRtmpConnType type)
{
client->req = req;
void SrsStatistic::on_disconnect(std::string id)
{
clients.erase(it);
// RTMP references Conn's req.
srs_error_t SrsRtmpConn::stream_service_cycle()
{
SrsRequest* req = info->req;
if ((err = stat->on_client(srs_int2str(_srs_context->get_id()), req, this, info->type)) != srs_success) {
// FLV references SrsLiveStream.
srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
{
if ((err = stat->on_client(srs_int2str(_srs_context->get_id()), req, hc, SrsRtmpConnPlay)) != srs_success) {
srs_error_t SrsLiveStream::update(SrsSource* s, SrsRequest* r)
{
srs_freep(req);
req = r->copy()->as_http(); This issue does not exist in RTMP because SrsStatistic references SrsRtmpConn's req, and the latter has a longer lifespan and is always available. This issue exists in HTTP-FLV and causes a crash. The reproduction steps are provided in the previous comment. The problem arises because SrsStatistic references SrsLiveStream's req, and the lifespans of these two objects are uncertain, resulting in SrsStatistic referencing a dangling pointer. Solution: Copy req in SrsStatistic. Since SrsStatistic and conn are corresponding, their req objects are also corresponding. Therefore, stat can be considered as one of conn's members and can be copied. Refer to 71dda68 for more details. Once again, thank you @duiniuluantanqin for spending a lot of time analyzing and locating this issue. This kind of wild pointer problem is very subtle, and the most difficult part is how to locate it. Once located, it is easy to fix.
|
Thank you two experts, the problem has been resolved.
|
Accessing the client through the HTTP interface /api/v1/clients/?start=0&count=1000 may cause the SRS service to restart intermittently.
Please describe the issue you encountered.
1. SRS version:
SRS/3.0.137(OuXuli)
1. SRS log:
1. SRS configuration:
Replay
How to replay bug?
Bug Reproduction Steps:
/api/v1/clients?start=0&count=1000
interface will cause the service to restart.Please note that the translation provided is a direct translation and may require further clarification or adjustment based on the context.
TRANS_BY_GPT3
The text was updated successfully, but these errors were encountered: