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.9k stars 5.4k forks source link

SIGPIPE: Press the Esc key to exit ffplay while pulling the rtmp stream. #1961

Closed dragon8609 closed 4 years ago

dragon8609 commented 4 years ago

Description'

Please ensure that the markdown structure is maintained.

Describe the problem you encountered here: (1) Pushing stream to SRS using ffmpeg. (2) Then playing the RTMP stream using ffplay. When the ffmpeg stream is not finished, pressing the Esc key to exit ffplay causes the SRS process to crash and exit.

  1. SRS version: 3.0.143
  2. The log of SRS is as follows:
    
    [root@localhost trunk]# gdb --args ./objs/srs -c conf/console.conf 
    GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-119.el7
    Copyright (C) 2013 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "x86_64-redhat-linux-gnu".
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>...
    Reading symbols from /root/Desktop/srs_clear/srs/trunk/objs/srs...done.
    (gdb) r
    Starting program: /root/Desktop/srs_clear/srs/trunk/./objs/srs -c conf/console.conf
    [2020-09-22 23:13:50.393][Trace][128490][0] XCORE-SRS/3.0.143(OuXuli)
    [2020-09-22 23:13:50.394][Trace][128490][0] config parse complete
    [2020-09-22 23:13:50.394][Trace][128490][0] write log to console
    [2020-09-22 23:13:50.394][Trace][128490][0] SRS/3.0.143(OuXuli), The MIT License (MIT)
    [2020-09-22 23:13:50.394][Trace][128490][0] contributors: winlin<winlin@vip.126.com> wenjie.zhao<740936897@qq.com> xiangcheng.liu<liuxc0116@foxmail.com> naijia.liu<youngcow@youngcow.net> alcoholyi<alcoholyi@qq.com> byteman<wangchen2011@gmail.com> chad.wang<chad.wang.cn@gmail.com> suhetao<suhetao@gmail.com> Johnny<fengjihu@163.com> karthikeyan<keyanmca@gmail.com> StevenLiu<lq@chinaffmpeg.org> zhengfl<zhengfl_1989@126.com> tufang14<breadbean1449@gmail.com> allspace<allspace@gmail.com> niesongsong<nie950@gmail.com> rudeb0t<nimrod@themanxgroup.tw> CallMeNP<np.liamg@gmail.com> synote<synote@qq.com> lovecat<littlefawn@163.com> panda1986<542638787@qq.com> YueHonghui<hongf.yue@hotmail.com> ThomasDreibholz<dreibh@simula.no> JuntaoLiu<juntliu@gmail.com> RocFang<fangpeng1986@gmail.com> MakarovYaroslav<yaroslav.makarov.97@mail.ru> MirkoVelic<mvelic@inoxx.net> HuiZhang(huzhang2)<huzhang2@cisco.com> OtterWa<simpleotter23@gmail.com> walkermi<172192667@qq.com> haofz<fuzhuang.hao@vhall.com> ME_Kun_Han<hanvskun@hotmail.com> ljx0305<ljx0305@gmail.com> cenxinwei<censhanhe@163.com> StarBrilliant<m13253@hotmail.com> xubin<xubin@chnvideo.com> intliang<yintiliang@gmail.com> flowerwrong<sysuyangkang@gmail.com> YLX<568414379@qq.com> J<guotaojiang@qq.com> Harlan<hailiang@gvrcraft.com> hankun<hankun@bravovcloud.com> JonathanBarratt<jonathan.barratt@gmail.com> KeeganH<keeganwharris@gmail.com> StevenLiu<lingjiujianke@gmail.com> liuxc0116<liuxc0116@gmail.com> ChengdongZhang<lmajzcd@sina.com> lovacat<lovecat@china.sina.com> qiang.li<qiang.li@verycdn.com.cn> HungMingWu<u9089000@gmail.com> Himer<xishizhaohua@qq.com> xialixin<xlx0625@163.com> alphonsetai<tyh_123@163.com> Michael.Ma<wnpllr@gmail.com> lam2003<linmin3@yy.com> l<22312935+lam2003@users.noreply.github.com> xfalcon<x-falcon@users.noreply.github.com> 
    [2020-09-22 23:13:50.394][Trace][128490][0] cwd=/root/Desktop/srs_clear/srs/trunk, work_dir=./, build: 2020-09-22 23:03:03, configure: --x86-x64 , uname: Linux localhost.localdomain 3.10.0-1127.el7.x86_64 #1 SMP Tue Mar 31 23:36:51 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux, osx: 0
    [2020-09-22 23:13:50.394][Trace][128490][0] configure detail: --prefix=/usr/local/srs --with-hls --with-hds --with-dvr --with-ssl --with-transcode --with-ingest --with-stat --with-http-callback --with-http-server --with-stream-caster --with-http-api --with-librtmp --without-research --without-utest --without-gperf --without-gmc --without-gmd --without-gmp --without-gcp --without-gprof --log-trace --cc=gcc --cxx=g++ --ar=ar --ld=ld --randlib=randlib
    [2020-09-22 23:13:50.395][Trace][128490][0] srs checking config...
    [2020-09-22 23:13:50.398][Trace][128490][0] ips, iface[0] ens33 ipv4 0x11043 10.21.8.188, iface[1] ens33 ipv6 0x11043 fe80::aedf:61da:4bd7:7bab5.093722e-317ns33
    [2020-09-22 23:13:50.398][Trace][128490][0] devices, intranet ens33 10.21.8.188, intranet ens33 fe80::aedf:61da:4bd7:7bab5.093722e-317ns33
    [2020-09-22 23:13:50.398][Warn][128490][0][0] stats network use index=0, ip=10.21.8.188
    [2020-09-22 23:13:50.398][Warn][128490][0][0] stats disk not configed, disk iops disabled.
    [2020-09-22 23:13:50.398][Trace][128490][0] write log to console
    [2020-09-22 23:13:50.398][Trace][128490][0] features, rch:on, dash:on, hls:on, hds:on, hc:on, ha:on, hs:on, hp:on, dvr:on, trans:on, inge:on, stat:on, sc:on
    [2020-09-22 23:13:50.398][Trace][128490][0] SRS on  amd64 x86_64, conf:conf/console.conf, limit:1000, writev:1024, encoding:little-endian, HZ:100
    [2020-09-22 23:13:50.398][Trace][128490][0] mw sleep:350ms. mr enabled:on, default:0, sleep:350ms
    [2020-09-22 23:13:50.398][Trace][128490][0] gc:on, pq:30000ms, cscc:[0,16), csa:on, tn:on(may hurts performance), ss:auto(guess by merged write)
    [2020-09-22 23:13:50.398][Trace][128490][0] system default latency(ms): mw(0-350) + mr(0-350) + play-queue(0-30000)
    [2020-09-22 23:13:50.398][Warn][128490][0][0] SRS/3.0.143 is beta
    [2020-09-22 23:13:50.400][Trace][128490][0] http: root mount to ./objs/nginx/html
    [2020-09-22 23:13:50.400][Trace][128490][0] st_init success, use epoll
    [2020-09-22 23:13:50.400][Trace][128490][892] server main cid=892, pid=128490, ppid=128487, asprocess=0
    [2020-09-22 23:13:50.401][Trace][128490][892] write pid=128490 to ./objs/srs.pid success!
    [2020-09-22 23:13:50.402][Trace][128490][892] RTMP listen at tcp://0.0.0.0:1935, fd=11
    [2020-09-22 23:13:50.403][Trace][128490][892] HTTP-API listen at tcp://0.0.0.0:1985, fd=12
    [2020-09-22 23:13:50.403][Trace][128490][892] HTTP-Server listen at tcp://0.0.0.0:8080, fd=13
    [2020-09-22 23:13:50.403][Trace][128490][892] signal installed, reload=1, reopen=10, fast_quit=15, grace_quit=3
    [2020-09-22 23:13:50.403][Trace][128490][892] http: api mount /console to ./objs/nginx/html/console
    [2020-09-22 23:15:42.016][Trace][128490][898] RTMP client ip=10.21.8.227, fd=14
    [2020-09-22 23:15:42.032][Trace][128490][898] complex handshake success
    [2020-09-22 23:15:42.072][Trace][128490][898] connect app, tcUrl=rtmp://10.21.8.188:1935/live, pageUrl=, swfUrl=, schema=rtmp, vhost=10.21.8.188, port=1935, app=live, args=null
    [2020-09-22 23:15:42.072][Trace][128490][898] protocol in.buffer=0, in.ack=0, out.ack=0, in.chunk=128, out.chunk=128
    [2020-09-22 23:15:42.314][Trace][128490][898] client identified, type=fmle-publish, vhost=10.21.8.188, app=live, stream=test, param=, duration=0ms
    [2020-09-22 23:15:42.314][Trace][128490][898] connected stream, tcUrl=rtmp://10.21.8.188:1935/live, pageUrl=, swfUrl=, schema=rtmp, vhost=__defaultVhost__, port=1935, app=live, stream=test, param=, args=null
    [2020-09-22 23:15:42.314][Trace][128490][898] source url=/live/test, ip=10.21.8.227, cache=1, is_edge=0, source_id=-1[-1]
    [2020-09-22 23:15:42.555][Trace][128490][898] ignore disabled exec for vhost=__defaultVhost__
    [2020-09-22 23:15:42.555][Trace][128490][898] start publish mr=0/350, p1stpt=20000, pnt=5000, tcp_nodelay=0
    [2020-09-22 23:15:42.798][Trace][128490][898] got metadata, width=1280, height=720, vcodec=7, acodec=10
    [2020-09-22 23:15:42.799][Trace][128490][898] 45B video sh,  codec(7, profile=Baseline, level=3.1, 1280x720, 0kbps, 0.0fps, 0.0s)
    [2020-09-22 23:15:42.799][Trace][128490][898] 4B audio sh, codec(10, profile=LC, 2channels, 0kbps, 44100HZ), flv(16bits, 2channels, 44100HZ)
    [2020-09-22 23:15:43.839][Trace][128490][899] RTMP client ip=10.21.8.227, fd=15
    [2020-09-22 23:15:43.844][Trace][128490][899] complex handshake success
    [2020-09-22 23:15:43.885][Trace][128490][899] connect app, tcUrl=rtmp://10.21.8.188:1935/live, pageUrl=, swfUrl=, schema=rtmp, vhost=10.21.8.188, port=1935, app=live, args=null
    [2020-09-22 23:15:43.885][Trace][128490][899] protocol in.buffer=0, in.ack=0, out.ack=0, in.chunk=128, out.chunk=128
    [2020-09-22 23:15:44.126][Trace][128490][899] ignore AMF0/AMF3 command message.
    [2020-09-22 23:15:44.167][Trace][128490][899] ignore AMF0/AMF3 command message.
    [2020-09-22 23:15:44.167][Trace][128490][899] client identified, type=Play, vhost=10.21.8.188, app=live, stream=test, param=, duration=-1ms
    [2020-09-22 23:15:44.167][Trace][128490][899] connected stream, tcUrl=rtmp://10.21.8.188:1935/live, pageUrl=, swfUrl=, schema=rtmp, vhost=__defaultVhost__, port=1935, app=live, stream=test, param=, args=null
    [2020-09-22 23:15:44.168][Trace][128490][899] source url=/live/test, ip=10.21.8.227, cache=1, is_edge=0, source_id=898[898]
    [2020-09-22 23:15:44.168][Trace][128490][899] dispatch cached gop success. count=13, duration=194
    [2020-09-22 23:15:44.168][Trace][128490][899] create consumer, active=1, queue_size=0.00, jitter=30000000
    [2020-09-22 23:15:44.168][Trace][128490][899] set fd=15, SO_SNDBUF=87040=>175000, buffer=350ms
    [2020-09-22 23:15:44.168][Trace][128490][899] start play smi=0ms, mw_sleep=350, mw_enabled=1, realtime=0, tcp_nodelay=0

Program received signal SIGPIPE, Broken pipe. 0x00007ffff70df3e7 in writev () from /lib64/libc.so.6 Missing separate debuginfos, use: debuginfo-install glibc-2.17-307.el7.1.x86_64 libgcc-4.8.5-39.el7.x86_64 libstdc++-4.8.5-39.el7.x86_64 (gdb) bt

0 0x00007ffff70df3e7 in writev () from /lib64/libc.so.6

1 0x00000000005a4723 in st_writev (fd=0xa519d0, iov=0xa51e90, iov_size=28, timeout=30000000) at io.c:582

2 0x00000000004aa760 in SrsStSocket::writev (this=0xa018f0, iov=0xa51e90, iov_size=28, nwrite=0x0)

at src/service/srs_service_st.cpp:568

3 0x00000000004818fd in srs_write_large_iovs (skt=0xa018f0, iovs=0xa51e90, size=28, pnwrite=0x0)

at src/protocol/srs_protocol_utility.cpp:340

4 0x000000000045f117 in SrsProtocol::do_iovs_send (this=0xa51d50, iovs=0xa51e90, size=28) at src/protocol/srs_rtmp_stack.cpp:599

5 0x000000000045f0df in SrsProtocol::do_send_messages (this=0xa51d50, msgs=0xa1f550, nb_msgs=14)

at src/protocol/srs_rtmp_stack.cpp:543

6 0x000000000046080a in SrsProtocol::send_and_free_messages (this=0xa51d50, msgs=0xa1f550, nb_msgs=14, stream_id=1)

at src/protocol/srs_rtmp_stack.cpp:825

7 0x0000000000466c6c in SrsRtmpServer::send_and_free_messages (this=0xa51d20, msgs=0xa1f550, nb_msgs=14, stream_id=1)

at src/protocol/srs_rtmp_stack.cpp:2271

8 0x00000000004c996e in SrsRtmpConn::do_playing (this=0xa51a60, source=0xa01620, consumer=0xa5b8c0, rtrd=0x7ffff7ee4660)

at src/app/srs_app_rtmp_conn.cpp:784

9 0x00000000004c8a57 in SrsRtmpConn::playing (this=0xa51a60, source=0xa01620) at src/app/srs_app_rtmp_conn.cpp:664

10 0x00000000004c75e4 in SrsRtmpConn::stream_service_cycle (this=0xa51a60) at src/app/srs_app_rtmp_conn.cpp:524

11 0x00000000004c6621 in SrsRtmpConn::service_cycle (this=0xa51a60) at src/app/srs_app_rtmp_conn.cpp:388

12 0x00000000004c557c in SrsRtmpConn::do_cycle (this=0xa51a60) at src/app/srs_app_rtmp_conn.cpp:209

13 0x00000000004c3916 in SrsConnection::cycle (this=0xa51ad8) at src/app/srs_app_conn.cpp:171

14 0x00000000004f8b24 in SrsSTCoroutine::cycle (this=0xa51ce0) at src/app/srs_app_st.cpp:198

15 0x00000000004f8b99 in SrsSTCoroutine::pfn (arg=0xa51ce0) at src/app/srs_app_st.cpp:213

16 0x00000000005a22f0 in _st_thread_main () at sched.c:337

17 0x00000000005a2a60 in st_thread_create (start=0xffffffffffffffff, arg=0xa51ce0, joinable=0, stk_size=5905134) at sched.c:616

18 0x00000000004f87e2 in SrsSTCoroutine::start (this=<error reading variable: Cannot access memory at address 0xffffffd9>)

at src/app/srs_app_st.cpp:119

Backtrace stopped: previous frame inner to this frame (corrupt stack?) (gdb)

1. The configuration of SRS is as follows:

The default console.conf.

no-daemon and write log to console config for srs.

@see full.conf for detail config.

listen 1935; max_connections 1000; daemon off; srs_log_tank console; http_api { enabled on; listen 1985; } http_server { enabled on; listen 8080; } vhost defaultVhost { }



**Replay**

**How to replay bug?**

> Steps to reproduce the bug

**Steps to reproduce the bug:**

1. Run SRS: `./objs/srs -c conf/console.conf`
2. Push stream using ffmpeg: `ffmpeg.exe -re -i test.mp4 -vcodec copy -acodec copy -f flv rtmp://10.21.8.188/live/test`
3. Play stream using ffplay: `ffplay rtmp://10.21.8.188/live/test`
4. After the video interface appears in ffplay, wait for one or two seconds, then press the Esc key to exit. SRS crashes.

**Expected behavior:**

The SRS should not crash when exiting ffplay by pressing the Esc key.

**Expected behavior:**

Ideally, the SRS should not crash and should print a "client disconnect" message in the logs when a client disconnects.

`TRANS_BY_GPT3`
dragon8609 commented 4 years ago

The reason for using gdb was reminded by someone in the group. If gdb is not used, there is no problem. Specifically, gdb caught the sigpipe signal and stopped the process.

TRANS_BY_GPT3

winlinvip commented 3 years ago

When using gdb, this SIGPIPE signal will be triggered, and it needs to be filtered manually.

Program received signal SIGPIPE, Broken pipe.
0x00007ffff70df3e7 in writev () from /lib64/libc.so.6
Missing separate debuginfos, use: debuginfo-install glibc-2.17-307.el7.1.x86_64 libgcc-4.8.5-39.el7.x86_64 libstdc++-4.8.5-39.el7.x86_64
(gdb) bt
#0  0x00007ffff70df3e7 in writev () from /lib64/libc.so.6

TRANS_BY_GPT3