Skip to content
Snippets Groups Projects
Commit c02641ef authored by Raphael Defosseux's avatar Raphael Defosseux
Browse files

Merge branch 'fix-http2-server-shutdown' into 'develop'

fix(http2): proper HTTP2 synchronous stop

See merge request !45
parents fa18a6f9 2d987a07
No related branches found
No related tags found
1 merge request!45fix(http2): proper HTTP2 synchronous stop
Pipeline #45438 passed
Subproject commit db9313335abd67c2b19394bc7bc9526861d1432c
Subproject commit fb0498f356198301621c5ca4da3e2c2fca4c9855
Subproject commit 20e11848df5037c582cee1861738498e8561a2ca
Subproject commit 30956f071e69d075ee70fc4c6fadcfc084a9da4d
......@@ -53,7 +53,7 @@ extern std::unique_ptr<pcf_config> pcf_cfg;
void pcf_http2_server::start() {
boost::system::error_code ec;
Logger::pcf_sbi().info("HTTP2 server started");
Logger::pcf_sbi().info("HTTP2 server being started");
std::string nfId = {};
std::string subscriptionID = {};
......@@ -168,13 +168,21 @@ void pcf_http2_server::start() {
return;
});
running_server = true;
if (server.listen_and_serve(ec, m_address, std::to_string(m_port))) {
Logger::pcf_sbi().error("HTTP Server error: %s", ec.message());
}
running_server = false;
Logger::pcf_sbi().info("HTTP2 server fully stopped");
}
void pcf_http2_server::stop() {
server.stop();
while (running_server) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
Logger::pcf_sbi().info("HTTP2 server should be fully stopped");
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
void pcf_http2_server::handle_method_not_exists(
......
......@@ -71,6 +71,7 @@ class pcf_http2_server {
util::uint_generator<uint32_t> m_promise_id_generator;
std::string m_address;
uint32_t m_port;
bool running_server;
nghttp2::asio_http2::server::http2 server;
......
......@@ -36,20 +36,19 @@ using namespace oai::pcf::api;
using namespace oai::config;
std::unique_ptr<pcf_app> pcf_app_inst;
// TODO Stefan: I am not happy with these global variables
// We could make a singleton getInstance in config
// or we handle everything in smf_app init and have a reference to config there
std::unique_ptr<pcf_config> pcf_cfg;
std::unique_ptr<PCFApiServer> pcf_api_server_1;
std::unique_ptr<pcf_http2_server> pcf_api_server_2;
std::unique_ptr<pcf_app> pcf_app_inst = nullptr;
std::unique_ptr<pcf_config> pcf_cfg = nullptr;
std::unique_ptr<PCFApiServer> pcf_api_server_1 = nullptr;
std::unique_ptr<pcf_http2_server> pcf_api_server_2 = nullptr;
//------------------------------------------------------------------------------
void signal_handler_sigint(int) {
std::cout << "Caught SIGINT signal " << std::endl;
Logger::system().startup("exiting");
std::cout << "Shutting down HTTP servers..." << std::endl;
void signal_handler_sigint(int s) {
// Setting log level arbitrarly to debug to show the whole
// shutdown procedure in the logs even in case of off-logging
Logger::set_level(spdlog::level::debug);
Logger::system().info("Exiting: caught signal %d", s);
Logger::system().debug("Shutting down HTTP servers...");
if (pcf_api_server_1) {
pcf_api_server_1->shutdown();
}
......@@ -61,10 +60,16 @@ void signal_handler_sigint(int) {
}
// TODO exit is not always clean, check again after complete refactor
// Ensure that objects are destructed before static libraries (e.g. Logger)
Logger::system().debug("Freeing Allocated memory...");
pcf_api_server_1 = nullptr;
pcf_api_server_2 = nullptr;
pcf_app_inst = nullptr;
pcf_cfg = nullptr;
Logger::system().debug("PCF APP memory done");
Logger::system().debug("Freeing allocated memory done");
Logger::system().info("Bye.");
exit(0);
}
//------------------------------------------------------------------------------
......
......@@ -46,7 +46,9 @@ class Logger {
oai::logger::logger_registry::register_logger(
name, SYSTEM, log_stdout, log_rot_file);
}
static void set_level(spdlog::level::level_enum level) {
oai::logger::logger_registry::set_level(level);
}
static const oai::logger::printf_logger& pcf_app() {
return oai::logger::logger_registry::get_logger(PCF_APP);
}
......@@ -58,4 +60,4 @@ class Logger {
static const oai::logger::printf_logger& system() {
return oai::logger::logger_registry::get_logger(SYSTEM);
}
};
\ No newline at end of file
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment