Closed winlinvip closed 10 months ago
First push the stream, then change hls_ctx, then reload, it will crash.
TRANS_BY_GPT4
ok, i will check it as soon as possible
My reproduction steps:
SRS configuration: srs.conf.ctx_on (hls_ctx is enabled by default)
listen 1935;
max_connections 1000;
srs_log_tank file;
srs_log_file ./objs/srs.log;
daemon on;
http_api {
enabled on;
listen 1985;
raw_api {
enabled on;
allow_reload on;
}
}
http_server {
enabled on;
listen 8080;
dir ./objs/nginx/html;
}
rtc_server {
enabled on;
listen 8000; # UDP port
# @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#config-candidate
candidate $CANDIDATE;
}
vhost __defaultVhost__ {
http_hooks {
enabled on;
on_hls http://127.0.0.1:8085/api/v1/hls;
}
hls {
enabled on;
}
http_remux {
enabled on;
mount [vhost]/[app]/[stream].flv;
}
rtc {
enabled on;
# @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#rtmp-to-rtc
rtmp_to_rtc on;
# @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#rtc-to-rtmp
rtc_to_rtmp on;
}
play{
gop_cache_max_frames 2500;
}
}
srs.conf.ctx_off
listen 1935;
max_connections 1000;
srs_log_tank file;
srs_log_file ./objs/srs.log;
daemon on;
http_api {
enabled on;
listen 1985;
raw_api {
enabled on;
allow_reload on;
}
}
http_server {
enabled on;
listen 8080;
dir ./objs/nginx/html;
}
rtc_server {
enabled on;
listen 8000; # UDP port
# @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#config-candidate
candidate $CANDIDATE;
}
vhost __defaultVhost__ {
http_hooks {
enabled on;
on_hls http://127.0.0.1:8085/api/v1/hls;
}
hls {
enabled on;
hls_ctx off;
hls_ts_ctx off;
}
http_remux {
enabled on;
mount [vhost]/[app]/[stream].flv;
}
rtc {
enabled on;
# @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#rtmp-to-rtc
rtmp_to_rtc on;
# @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#rtc-to-rtmp
rtc_to_rtmp on;
}
play{
gop_cache_max_frames 2500;
}
}
Start srs
./objs/srs -c conf/srs.conf
Start backend server
Wait for 10s in /api/v1/hls, such as
// handle the dvrs requests: on_hls stream.
http.HandleFunc("/api/v1/hls", func(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
SrsWriteDataResponse(w, struct{}{})
return
}
if err := func() error {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
return fmt.Errorf("read request body, err %v", err)
}
log.Println(fmt.Sprintf("post to hls, req=%v", string(body)))
msg := &SrsHlsRequest{}
if err := json.Unmarshal(body, msg); err != nil {
return fmt.Errorf("parse message from %v, err %v", string(body), err)
}
log.Println(fmt.Sprintf("Got %v", msg.String()))
time.Sleep(10 * time.Second)
log.Println("after sleep")
if !msg.IsOnHls() {
return fmt.Errorf("invalid message %v", msg.String())
}
SrsWriteDataResponse(w, &SrsCommonResponse{Code: 0})
return nil
}(); err != nil {
SrsWriteErrorResponse(w, err)
}
})
cd research/api-server
go run server.go
Push stream
ffmpeg -stream_loop -1 -re -i doc/source.200kbps.768x320.flv -c copy -f flv "rtmp://127.0.0.1/live/livestream"
Loop reload
#!/bin/bash
i=1
cur_pid=$(pgrep "srs")
while [ $i -le 1000000 ] do let i++ echo "$i"
sleep 10
cp conf/srs.conf.ctx_on conf/srs.conf kill -1 $cur_pid
pid=$(pgrep "srs") echo $(date +%T)" reload signo, srs pid=$pid"
sleep 10
cp conf/srs.conf.ctx_off conf/srs.conf kill -1 $cur_pid
pid=$(pgrep "srs") echo $(date +%T)" reload signo, srs pid=$pid" done
5. Wait for SRS crash
`TRANS_BY_GPT4`
Description
Please description your issue here
SRS Version: 5.0.170
SRS Log:
Replay
Please describe how to replay the bug?
Step 1: Run SRS, with HLS and on_hls callback.
Step 2: Set
hls_ctx on;
and publish stream.Step 3: Set the field
hls_ctx off;
and reload SRS.Crashed.
In on_hls, sleep 60s to simulate slow API server.
Expect
No crash.