Skip to content

Commit

Permalink
For #1579, support start/final wait for gracefully quit. 3.0.121
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Feb 18, 2020
1 parent 58b4047 commit dc0f804
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions trunk/conf/full.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion trunk/src/app/srs_app_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core_version3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit dc0f804

Please sign in to comment.