winshining / nginx-http-flv-module

A media streaming server based on nginx-rtmp-module. In addtion to the features nginx-rtmp-module provides, HTTP-FLV, GOP cache, VHosts (one IP for multi domain names) and JSON style statistics are supported now.
BSD 2-Clause "Simplified" License
2.74k stars 571 forks source link

reload的问题 #30

Open han4235 opened 6 years ago

han4235 commented 6 years ago

如果有推流, 然后nginx服务在reload的时候, shut_down的进程关闭不了, 除非推流断开,请问这个有没有啥好的思路来改进一下?

winshining commented 6 years ago

reload连接暂时不断开的设计初衷是在不断开现有连接的情况下可以热更新nginx,要改得改nginx本身的源代码,不打算支持

han4235 commented 6 years ago

恩, 我们只是讨论下这个问题, 这个问题其实蛮严重的, 按照nginx原生的设计原理, reload是重新开启进程,原有的进程之上的链接直至全部断开才会停用, 并且原有的进程不会再继续监听端口, 新的链接请求会被分配到新的进程,这样造成的后果,原来的推流一直在, 但是客户端再去拉流,其实是拉不到流的。

han4235 commented 6 years ago

我倒是有个思路, 类似于rtmp_auto_push,服务reload之后, 老进程里面保留的推流, 主动往新进程推送, 这样保证新链接进来之后, 能够从新的进程里拉到流, 同时也不破坏nginx原有的机制, 老进程的链接都正常消亡之后, 再推出,流自然断开之后, 就顺利被新进程接管了。

winshining commented 6 years ago

老的进程怎么知道新进程的信息,这点很关键

han4235 commented 6 years ago

已经修改好了, 其实很简单,在ngx_rtmp_auto_push_reconnect这个接口里面稍微修改一下

han4235 commented 6 years ago

将定时器开启, 推流进程自动会检测是否有新进程, 然后再把流推过去就好了, 这样新老进程都有流, 当推流结束的时候, 老进程就会自然消亡。

DoM1niC commented 6 years ago

winshining its time to say THX 2 for this nice NGINX RTMP Fork!!!

I can't read thai or so... I hope it's the same problem like me, after NGINX Reload the FLV Stream isn't available anymore, I need to reconnect the Stream like in OBS to recreate the URL. Could you tell me how to fix it... The Problem is I build a own Webinterface their create automatic a conf file 4 the RTMP, after this I need to reload NGINX.

winshining commented 6 years ago

@DoM1niC Yes, the issue is about what you think. But I'm afraid that we can hardly fix the problem. When Nginx reloads, the old processes will check if there are some connections between the server and the clients, so they won't exit until finishing to serve the last connection. However, during that time, the old processes will not accept new connections and the new spawned processes are ready to do the job, so if you close the FLV stream while you are still pushing stream, the old processes will not exit and will not accept new FLV connections. At this time, you initialize a connection to the server, the new process accept the connection, but the pushing stream is on the old one still, that is the reason why you can not play the FLV stream. This is the mechanism of Nginx, one solution is to add dynamic config file parsing feature, then we can reload the config file without reloading Nginx. Nginx-Plus has the feature we want, but it is not open source:( BTW, the language you see above is not Thai but Chinese:)

HeyJupiter commented 6 years ago

@DoM1niC Hi, do you use this module in production?

DoM1niC commented 5 years ago

This here :) @HeyJupiter

btw. @winshining Reloading is no more necessary I switched to a own on_publish PHP Script 2 handle all coming Updates with ne Streams aka Users, the best thing Broadcast / Stream App are bridge to resolve other Stream Names in production. Multistreaming is working too easy header redirecting for other RTMP Services.

Notice notify musst POST and the stream key name is send by default like $name =$_POST["name"]; or for App -> $app=$_POST["app"];

Read on_publish Directives to unterstand more what I wrote :D

chundonglinlin commented 2 years ago

The old shutting_down worker can still listen on a port to provide services by using per _worker config.