Skip to content
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

When encoding the data chunk returned by the HTTP callback, parsing the body will fail. #1678

Closed
alex03226 opened this issue Mar 30, 2020 · 3 comments
Assignees
Labels
Bug It might be a bug. TransByAI Translated by AI/GPT.
Milestone

Comments

@alex03226
Copy link

alex03226 commented Mar 30, 2020

Description

When on_connect, request the HTTP service and the server returns: (captured by Wireshark)
HTTP/1.1 200
Access-Control-Allow-Methods: GET,POST,OPTIONS,PUT,DELETE
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Fri, 27 Mar 2020 05:29:20 GMT

45
{"code":0,"token":"de53ddf1c533250c6a5ce1067e1a21e4a84ad1537634b48b"}
0

Description

At that time, the HTTP parsing will fail.

Description

  1. SRS version: 3.0.63
  2. The log of SRS is as follows:
[2020-03-30 05:47:17.687][Error][850][106][11] connect error code=3008 : service cycle : rtmp: stream service : check vhost : rtmp: callback on connect : http: on_check failed, stream=dev1, url=http://192.168.8.223:80/device/check, request={"action":"on_check","device_id":"dev1","timestamp":"270525051"}, response=, code=200 : http: empty response
thread #104: do_cycle() [src/app/srs_app_rtmp_conn.cpp:214][errno=11]
thread #104: service_cycle() [src/app/srs_app_rtmp_conn.cpp:404][errno=11]
thread #104: stream_service_cycle() [src/app/srs_app_rtmp_conn.cpp:467][errno=11]
thread #104: check_vhost() [src/app/srs_app_rtmp_conn.cpp:591][errno=11]
thread #104: on_license_check() [src/app/srs_app_http_hooks.cpp:89][errno=11]
thread #104: do_post_2() [src/app/srs_app_http_hooks.cpp:620][errno=11](Resource temporarily unavailable)

Description

Compared to v2.0, I made the following modifications:

  1. srs_http_stack.cpp: line 1592
    uint32_t nread = parser->nread; -> uint32_t &nread = parser->nread;
    Description
  2. srs_service_http_conn.cpp: line 120
#if 0     // When receiving data in Chunk mode, it caused the loss of Chunk header size
        if (pbody && buffer->bytes() < pbody) {
           consumed = pbody - buffer->bytes();
        }

#else
if (header.nread > 0)
consumed = header.nread;
#endif

Expectation: I don't know if the changes made are appropriate.

TRANS_BY_GPT3

@alex03226 alex03226 reopened this Mar 30, 2020
@alex03226 alex03226 reopened this Mar 30, 2020
@alex03226 alex03226 reopened this Mar 30, 2020
@winlinvip
Copy link
Member

winlinvip commented Mar 30, 2020

This problem has already been modified, please verify if the latest SRS3 still has this problem.

TRANS_BY_GPT3

@alex03226
Copy link
Author

alex03226 commented Mar 31, 2020

3.0.140 New version is normal

TRANS_BY_GPT3

@Zhoutzzz
Copy link

Zhoutzzz commented Jul 10, 2020

In version 3.0.141, I encountered the same error when using OBS for streaming. Upon observing the logs, I found that the connection was closed immediately after establishing a connection with SRS. Everything works fine when streaming without any configuration, but this issue occurs when configuring callbacks.

The complete log when streaming with SRS is as follows:
[2020-07-10 15:31:55.626][Trace][1956][764] RTMP client ip=192.168.119.1, fd=9
[2020-07-10 15:31:55.637][Trace][1956][764] simple handshake success.
[2020-07-10 15:31:55.637][Trace][1956][764] connect app, tcUrl=rtmp://192.168.119.128:1935/test/live, pageUrl=, swfUrl=rtmp://192.168.119.128:1935/test/live, schema=rtmp, vhost=192.168.119.128, port=1935, app=test/live, args=null
[2020-07-10 15:31:55.637][Trace][1956][764] protocol in.buffer=0, in.ack=0, out.ack=0, in.chunk=4096, out.chunk=128
[2020-07-10 15:31:55.841][Trace][1956][764] client identified, type=fmle-publish, vhost=192.168.119.128, app=test/live, stream=benhuai3, param=, duration=0ms
[2020-07-10 15:31:55.866][Warn][1956][764][11] http: ignore on_close failed, client_id=764, url=http://10.1.10.185:29517/api/srs/callback, request={"action":"on_close","client_id":764,"ip":"192.168.119.1","vhost":"defaultVhost","app":"test/live","send_bytes":3656,"recv_bytes":3344}, response=, code=200, ret=3008
[2020-07-10 15:31:55.867][Error][1956][764][11] serve error code=3008 : service cycle : rtmp: stream service : check vhost : rtmp: callback on connect : rtmp on_connect http://10.1.10.185:29517/api/srs/callback : http: on_connect failed, client_id=764, url=http://10.1.10.185:29517/api/srs/callback, request={"action":"on_connect","client_id":764,"ip":"192.168.119.1","vhost":"defaultVhost","app":"test/live","tcUrl":"rtmp://192.168.119.128:1935/test/live","pageUrl":""}, response=, code=200 : http: empty response
thread [1956][764]: do_cycle() [src/app/srs_app_rtmp_conn.cpp:210][errno=11]
thread [1956][764]: service_cycle() [src/app/srs_app_rtmp_conn.cpp:399][errno=11]
thread [1956][764]: stream_service_cycle() [src/app/srs_app_rtmp_conn.cpp:462][errno=11]
thread [1956][764]: check_vhost() [src/app/srs_app_rtmp_conn.cpp:586][errno=11]
thread [1956][764]: http_hooks_on_connect() [src/app/srs_app_rtmp_conn.cpp:1243][errno=11]
thread [1956][764]: on_connect() [src/app/srs_app_http_hooks.cpp:83][errno=11]
thread [1956][764]: do_post() [src/app/srs_app_http_hooks.cpp:509][errno=11](Resource temporarily unavailable)

The configuration file used by SRS is as follows:
listen 1935;
max_connections 1000;
srs_log_tank console;
#srs_log_file ./objs/srs.log;
http_api {
enabled on;
listen 1985;
}
#http_server {
#enabled on;
#listen 8080;
#dir ./objs/nginx/html;
#}
#stats {
#network 0;
#disk sda sdb xvda xvdb;
#}
vhost defaultVhost {
http_hooks {
enabled on;
on_connect http://10.1.10.185:29517/api/srs/callback;
on_close http://10.1.10.185:29517/api/srs/callback;
on_publish http://10.1.10.185:29517/api/srs/callback;
on_unpublish http://10.1.10.185:29517/api/srs/callback;
on_play http://10.1.10.185:29517/api/srs/callback;
on_stop http://10.1.10.185:29517/api/srs/callback;
}

}

TRANS_BY_GPT3

@winlinvip winlinvip self-assigned this Sep 4, 2021
@winlinvip winlinvip added the Bug It might be a bug. label Sep 4, 2021
@winlinvip winlinvip added this to the 4.0 milestone Sep 4, 2021
@winlinvip winlinvip changed the title http callback 返回数据 chunk 编码时,解析body会失败 When encoding the data chunk returned by the HTTP callback, parsing the body will fail. Jul 28, 2023
@winlinvip winlinvip added the TransByAI Translated by AI/GPT. label Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug It might be a bug. TransByAI Translated by AI/GPT.
Projects
None yet
Development

No branches or pull requests

3 participants