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.87k stars 5.39k forks source link

Webrtc over tcp use same port with Http Server and Http Api will cause http site unavailable #4123

Closed chkzack closed 4 months ago

chkzack commented 4 months ago

When I use same port with Http Server and Http Api to use Webrtc over tcp, reference to WebRTC over TCP, will cause http site unavailable.

Here is the error:

[2024-07-19 03:20:11.014][INFO][1][61x9532u] XCORE-SRS/5.0.210(Bee)
[2024-07-19 03:20:11.021][INFO][1][61x9532u] config parse complete
[2024-07-19 03:20:11.021][INFO][1][61x9532u] enable in_docker by config
[2024-07-19 03:20:11.021][INFO][1][61x9532u] write log to console
[2024-07-19 03:20:11.022][INFO][1][61x9532u] SRS/5.0.210(Bee), MIT
[2024-07-19 03:20:11.022][INFO][1][61x9532u] authors: Winlin<winlin@vip.126.com> ZhaoWenjie<zhaowenjie@tal.com> ShiWei<shiwei05@kuaishou.com> XiaoZhihong<hondaxiao@tencent.com> WuPengqiang<pengqiang.wpq@alibaba-inc.com> XiaLixin<xialixin@kanzhun.com> LiPeng<mozhan.lp@alibaba-inc.com> ChenGuanghua<jinxue.cgh@alibaba-inc.com> ChenHaibo<nmgchenhaibo@foxmail.com> and https://github.com/ossrs/srs/blob/develop/trunk/AUTHORS.md#contributors       
[2024-07-19 03:20:11.022][INFO][1][61x9532u] cwd=/usr/local/srs, work_dir=./, build: 2024-04-03 07:07:39, configure: --sanitizer=off --gb28181=on, uname: Linux buildkitsandbox 5.15.0-1059-azure #67~20.04.1-Ubuntu SMP Tue Mar 12 18:58:58 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux, osx: 0, env: 1, pkg: dcis
[2024-07-19 03:20:11.022][INFO][1][61x9532u] configure detail: --prefix=/usr/local/srs --config=conf/srs.conf --osx=off --hls=on --hds=off --dvr=on --ssl=on --https=on --ssl-1-0=off --ssl-local=off --sys-ssl=off --transcode=on --ingest=on --stat=on --http-callback=on --http-server=on --stream-converter=on --http-api=on --utest=off --srt=on --sys-srt=off --rtc=on --gb28181=on --simulator=off --cxx11=on --cxx14=off --backtrace=on --ffmpeg-fit=on --sys-ffmpeg=off --ffmpeg-opus=off --nasm=on --srtp-nasm=on --sys-srtp=off --clean=on --gperf=off --gmc=off --gmd=off --gmp=off --gcp=off --gprof=off --static=off --shared-st=off --shared-srt=reserved --shared-ffmpeg=reserved --shared-srtp=reserved --log-verbose=off --log-info=off --log-trace=on --log-level_v2=on --gcov=off --apm=off --debug=off --debug-stats=off --cross-build=off --sanitizer=off --sanitizer-static=off --sanitizer-log=off --cygwin64=off --single-thread=off --generic-linux=off --build-cache=on --cc=gcc --cxx=g++ --ar=ar --ld=ld --randlib=randlib
[2024-07-19 03:20:11.022][INFO][1][61x9532u] srs checking config...
[2024-07-19 03:20:11.028][INFO][1][61x9532u] ips, iface[0] eth0 ipv4 0x11043 172.17.0.2, iface[1] eth0 ipv6 0x11043 fe80::42:acff:fe11:2%eth0
[2024-07-19 03:20:11.028][INFO][1][61x9532u] devices, intranet eth0 172.17.0.2, intranet eth0 fe80::42:acff:fe11:2%eth0
[2024-07-19 03:20:11.028][WARN][1][61x9532u][2] stats network use index=0, ip=172.17.0.2, ifname=eth0
[2024-07-19 03:20:11.028][WARN][1][61x9532u][2] stats disk list: sda sdb xvda xvdb
[2024-07-19 03:20:11.028][INFO][1][61x9532u] write log to console
[2024-07-19 03:20:11.028][INFO][1][61x9532u] features, rch:on, dash:on, hls:on, hds:off, srt:on, hc:on, ha:on, hs:on, hp:on, dvr:on, trans:on, inge:on, stat:on, sc:on
[2024-07-19 03:20:11.028][INFO][1][61x9532u] SRS on amd64 x86_64, conf:objs/nginx/html/share/docker.conf, limit:1000, writev:1024, encoding:little-endian, HZ:100
[2024-07-19 03:20:11.028][INFO][1][61x9532u] mw sleep:350ms. mr enabled:on, default:0, sleep:350ms
[2024-07-19 03:20:11.029][INFO][1][61x9532u] gc:on, pq:30000ms, cscc:[0,16), csa:on, tn:on(may hurts performance), ss:auto(guess by merged write)
[2024-07-19 03:20:11.029][INFO][1][61x9532u] system default latency(ms): mw(0-350) + mr(0-350) + play-queue(0-30000)
[2024-07-19 03:20:11.029][INFO][1][61x9532u] write pid=1 to ./objs/srs.pid success!
[2024-07-19 03:20:11.029][INFO][1][61x9532u] Thread #1(primordial): init name=srs-master-1, interval=5000ms
[2024-07-19 03:20:11.029][INFO][1][61x9532u] Pool: Start threads primordial=1, hybrids=1 ok
[2024-07-19 03:20:11.029][INFO][1][51hj011p] Thread #2: run with tid=7, entry=0x55ef32a178d0, label=hybrid, name=srs-hybrid-2
[2024-07-19 03:20:11.049][INFO][1][51hj011p] fingerprint=57:CE:A6:9A:A6:F1:89:F0:BA:61:0E:A5:65:A2:4A:98:F0:BF:67:79:86:E5:CB:9A:4A:4E:94:2B:69:04:30:C7
[2024-07-19 03:20:11.049][INFO][1][51hj011p] CircuitBreaker: enabled=1, high=2x90, critical=1x95, dying=5x99
[2024-07-19 03:20:11.049][INFO][1][51hj011p] WebRTC tcp=8090 reuses http=8090 server
[2024-07-19 03:20:11.049][INFO][1][51hj011p] API reuses http=8090 and https=443 server
[2024-07-19 03:20:11.049][INFO][1][51hj011p] http flv live stream, vhost=__defaultVhost__, mount=[vhost]/[app]/[stream].flv
[2024-07-19 03:20:11.049][INFO][1][51hj011p] http: root mount to ./objs/nginx/html
[2024-07-19 03:20:11.049][INFO][1][51hj011p] server main cid=51hj011p, pid=1, ppid=0, asprocess=0
[2024-07-19 03:20:11.049][INFO][1][51hj011p] RTMP listen at tcp://0.0.0.0:1935, fd=9
[2024-07-19 03:20:11.049][INFO][1][51hj011p] HTTP-API: Reuse listen to http server 8090
[2024-07-19 03:20:11.049][INFO][1][51hj011p] HTTP-Server listen at tcp://0.0.0.0:8090, fd=10
[2024-07-19 03:20:11.049][INFO][1][51hj011p] signal installed, reload=1, reopen=10, fast_quit=15, grace_quit=3
[2024-07-19 03:20:11.049][INFO][1][51hj011p] http: api mount /console to ./objs/nginx/html/console
[2024-07-19 03:20:11.050][INFO][1][51hj011p] srt listen at udp://0.0.0.0:10080, fd=151516337
[2024-07-19 03:20:11.050][INFO][1][51hj011p] rtc listen at udp://0.0.0.0:8000, fd=12
[2024-07-19 03:20:11.051][INFO][1][50h5qi27] Hybrid cpu=0.00%,23MB
[2024-07-19 03:20:11.051][INFO][1][q7510j1b] TCP: connection manager run, conns=0
[2024-07-19 03:20:11.051][WARN][1][51hj011p][11] enable auto reload for docker
[2024-07-19 03:20:11.051][INFO][1][51hj011p] auto reload watching fd=13, watch=1, file=objs/nginx/html/share
[2024-07-19 03:20:11.051][INFO][1][d625ga04] GB: connection manager run, conns=0
[2024-07-19 03:20:11.054][INFO][1][i9998432] SRT: connection manager run, conns=0
[2024-07-19 03:20:11.054][INFO][1][hf361i07] UDP #12 LISTEN at 0.0.0.0:8000, SO_SNDBUF(default=212992, expect=10485760, actual=425984, r0=0), SO_RCVBUF(default=212992, expect=10485760, actual=425984, r0=0)
[2024-07-19 03:20:11.054][INFO][1][91390007] RTC: connection manager run, conns=0
[2024-07-19 03:20:14.220][INFO][1][4xn1sg07] TCP: before dispose resource(HttpsConn)(0x7efe08078570), conns=1, zombies=0, ign=0, inz=0, ind=0
[2024-07-19 03:20:14.221][ERROR][1][4xn1sg07][0] serve error code=4042(HttpsHandshake)(Failed to do handshake for HTTPS) : start : handshake : handshake r0=-1, r1=1
thread [1][4xn1sg07]: do_cycle() [./src/app/srs_app_http_conn.cpp:155][errno=0]
thread [1][4xn1sg07]: on_start() [./src/app/srs_app_http_conn.cpp:388][errno=0]
thread [1][4xn1sg07]: handshake() [./src/app/srs_app_conn.cpp:803][errno=0]

Here is the settings I used:

listen              1935;
max_connections     1000;
# For docker, please use docker logs to manage the logs of SRS.
# See https://docs.docker.com/config/containers/logging/
srs_log_tank        console;
daemon              off;
http_api {
    enabled         on;
    listen          8090;
    https {
        enabled off;
        listen 443;
        key ./conf/server.key;
        cert ./conf/server.crt;
    }
}
http_server {
    enabled         on;
    listen          8090;
    dir             ./objs/nginx/html;
    https {
        enabled off;
        listen 443;
        key ./conf/server.key;
        cert ./conf/server.crt;
    }
}
rtc_server {
    enabled on;
    listen 8000;
    tcp {
          enabled on;
          listen 8090;
        }
    protocol tcp;
    candidate $CANDIDATE;
}
srt_server {
    enabled on;
    listen 10080;
    maxbw 1000000000;
    connect_timeout 4000;
    peerlatency 180;
    recvlatency 180;
    latency 180;
    tsbpdmode off;
    tlpktdrop off;
    sendbuf 2000000;
    recvbuf 2000000;
}
vhost __defaultVhost__ {
    tcp_nodelay     on;
    min_latency     on;
    chunk_size      1024;
    play {
        gop_cache       on;
        queue_length    10;
        mw_latency      0;
    }
    publish {
        mr off;
    }
    hls {
        enabled     on;
    }
    srt {
        enabled     on;
        srt_to_rtmp on;
    }
    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;
    }
    http_remux {
        enabled     on;
        mount       [vhost]/[app]/[stream].flv;
    }
}

# For SRT to use vhost.
vhost srs.srt.com.cn {
}

stats {
    network         0;
    disk            sda sdb xvda xvdb;
}

and I use this command to run SRS in docker docker run --rm -it -p 1935:1935 -p 8090:8090 -p 8000:8000 --env CANDIDATE=* -p 10080:10080/udp -v d:/share/:/usr/local/srs/objs/nginx/html/share/ registry.cn-hangzhou.aliyuncs.com/ossrs/srs:5 ./objs/srs -c objs/nginx/html/share/docker.conf

I tested docker images like ossrs/srs:5 5.0.210(Bee) and ossrs/srs:v6.0-d6 6.0.134(Hang), and both of them have the same error. I also tested docker image ossrs/srs:v5.0.60 which can access to http web site, but can not play webrtc stream.

When use different ports, then all runs well.