From dc0f804452a5f8d4a919b43d59a06cb296b3aff7 Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 18 Feb 2020 23:37:11 +0800 Subject: [PATCH] For #1579, support start/final wait for gracefully quit. 3.0.121 --- README.md | 1 + trunk/conf/full.conf | 6 ++++++ trunk/src/app/srs_app_config.cpp | 13 +++++++++++++ trunk/src/app/srs_app_config.hpp | 2 ++ trunk/src/app/srs_app_server.cpp | 6 +++++- trunk/src/core/srs_core_version3.hpp | 2 +- 6 files changed, 28 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9bb47c2083..eb7664c918 100755 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2020-02-18, For [#1579][bug #1579], support start/final wait for gracefully quit. 3.0.121 * v3.0, 2020-02-18, For [#1579][bug #1579], support force gracefully quit. 3.0.120 * v3.0, 2020-02-18, For [#1579][bug #1579], support gracefully quit. 3.0.119 * v3.0, 2020-02-17, For [#1601][bug #1601], flush async on_dvr/on_hls events before stop. 3.0.118 diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index e535e84ce2..65d5ddb482 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -73,6 +73,12 @@ work_dir ./; # default: off asprocess off; +# For gracefully quit, wait for a while then close listeners, +# because K8S notify SRS with SIGQUIT and update Service simultaneously, +# maybe there is some new connections incoming before Service updated. +# @see https://github.com/ossrs/srs/issues/1595#issuecomment-587516567 +# default: 2300 +grace_start_wait 2300; # For gracefully quit, final wait for cleanup in milliseconds. # @see https://github.com/ossrs/srs/issues/1579#issuecomment-587414898 # default: 3200 diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index ea517ff7fc..3c0af54dec 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -3488,6 +3488,7 @@ srs_error_t SrsConfig::check_normal_config() && n != "http_server" && n != "stream_caster" && n != "utc_time" && n != "work_dir" && n != "asprocess" && n != "ff_log_level" && n != "grace_final_wait" && n != "force_grace_quit" + && n != "grace_start_wait" ) { return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal directive %s", n.c_str()); } @@ -4050,6 +4051,18 @@ bool SrsConfig::get_asprocess() return SRS_CONF_PERFER_FALSE(conf->arg0()); } +srs_utime_t SrsConfig::get_grace_start_wait() +{ + static srs_utime_t DEFAULT = 2300 * SRS_UTIME_MILLISECONDS; + + SrsConfDirective* conf = root->get("grace_start_wait"); + if (!conf || conf->arg0().empty()) { + return DEFAULT; + } + + return (srs_utime_t)(::atol(conf->arg0().c_str()) * SRS_UTIME_MILLISECONDS); +} + srs_utime_t SrsConfig::get_grace_final_wait() { static srs_utime_t DEFAULT = 3200 * SRS_UTIME_MILLISECONDS; diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index d835bf8469..2bd2882b3b 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -468,6 +468,8 @@ class SrsConfig virtual std::string get_work_dir(); // Whether use asprocess mode. virtual bool get_asprocess(); + // Get the start wait in ms for gracefully quit. + virtual srs_utime_t get_grace_start_wait(); // Get the final wait in ms for gracefully quit. virtual srs_utime_t get_grace_final_wait(); // Whether force to gracefully quit, never fast quit. diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 22d0f857e5..b82cb91975 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -543,6 +543,10 @@ void SrsServer::gracefully_dispose() { _srs_config->unsubscribe(this); + // Always wait for a while to start. + srs_usleep(_srs_config->get_grace_start_wait()); + srs_trace("start wait for %dms", srsu2msi(_srs_config->get_grace_start_wait())); + // prevent fresh clients. close_listeners(SrsListenerRtmpStream); close_listeners(SrsListenerHttpApi); @@ -574,7 +578,7 @@ void SrsServer::gracefully_dispose() #endif srs_usleep(_srs_config->get_grace_final_wait()); - srs_trace("final wait for another %dms", srsu2msi(_srs_config->get_grace_final_wait())); + srs_trace("final wait for %dms", srsu2msi(_srs_config->get_grace_final_wait())); } srs_error_t SrsServer::initialize(ISrsServerCycle* ch) diff --git a/trunk/src/core/srs_core_version3.hpp b/trunk/src/core/srs_core_version3.hpp index 4e9f290ae9..ac541b5e4e 100644 --- a/trunk/src/core/srs_core_version3.hpp +++ b/trunk/src/core/srs_core_version3.hpp @@ -24,6 +24,6 @@ #ifndef SRS_CORE_VERSION3_HPP #define SRS_CORE_VERSION3_HPP -#define SRS_VERSION3_REVISION 120 +#define SRS_VERSION3_REVISION 121 #endif