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

fix(http2): proper HTTP2 synchronous stop

parent fa18a6f9
No related branches found
No related tags found
1 merge request!45fix(http2): proper HTTP2 synchronous stop
Pipeline #45236 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; ...@@ -53,7 +53,7 @@ extern std::unique_ptr<pcf_config> pcf_cfg;
void pcf_http2_server::start() { void pcf_http2_server::start() {
boost::system::error_code ec; 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 nfId = {};
std::string subscriptionID = {}; std::string subscriptionID = {};
...@@ -168,13 +168,21 @@ void pcf_http2_server::start() { ...@@ -168,13 +168,21 @@ void pcf_http2_server::start() {
return; return;
}); });
running_server = true;
if (server.listen_and_serve(ec, m_address, std::to_string(m_port))) { if (server.listen_and_serve(ec, m_address, std::to_string(m_port))) {
Logger::pcf_sbi().error("HTTP Server error: %s", ec.message()); 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() { void pcf_http2_server::stop() {
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( void pcf_http2_server::handle_method_not_exists(
......
...@@ -71,6 +71,7 @@ class pcf_http2_server { ...@@ -71,6 +71,7 @@ class pcf_http2_server {
util::uint_generator<uint32_t> m_promise_id_generator; util::uint_generator<uint32_t> m_promise_id_generator;
std::string m_address; std::string m_address;
uint32_t m_port; uint32_t m_port;
bool running_server;
nghttp2::asio_http2::server::http2 server; nghttp2::asio_http2::server::http2 server;
......
...@@ -36,20 +36,22 @@ using namespace oai::pcf::api; ...@@ -36,20 +36,22 @@ using namespace oai::pcf::api;
using namespace oai::config; using namespace oai::config;
std::unique_ptr<pcf_app> pcf_app_inst; std::unique_ptr<pcf_app> pcf_app_inst = nullptr;
// TODO Stefan: I am not happy with these global variables // TODO Stefan: I am not happy with these global variables
// We could make a singleton getInstance in config // We could make a singleton getInstance in config
// or we handle everything in smf_app init and have a reference to config there // 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<pcf_config> pcf_cfg = nullptr;
std::unique_ptr<PCFApiServer> pcf_api_server_1; std::unique_ptr<PCFApiServer> pcf_api_server_1 = nullptr;
std::unique_ptr<pcf_http2_server> pcf_api_server_2; std::unique_ptr<pcf_http2_server> pcf_api_server_2 = nullptr;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void signal_handler_sigint(int) { void signal_handler_sigint(int s) {
std::cout << "Caught SIGINT signal " << std::endl; // Setting log level arbitrarly to debug to show the whole
Logger::system().startup("exiting"); // shutdown procedure in the logs even in case of off-logging
std::cout << "Shutting down HTTP servers..." << std::endl; 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) { if (pcf_api_server_1) {
pcf_api_server_1->shutdown(); pcf_api_server_1->shutdown();
} }
...@@ -61,10 +63,16 @@ void signal_handler_sigint(int) { ...@@ -61,10 +63,16 @@ void signal_handler_sigint(int) {
} }
// TODO exit is not always clean, check again after complete refactor // TODO exit is not always clean, check again after complete refactor
// Ensure that objects are destructed before static libraries (e.g. Logger) // 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_1 = nullptr;
pcf_api_server_2 = nullptr; pcf_api_server_2 = nullptr;
pcf_app_inst = nullptr; pcf_app_inst = nullptr;
pcf_cfg = 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 { ...@@ -46,7 +46,9 @@ class Logger {
oai::logger::logger_registry::register_logger( oai::logger::logger_registry::register_logger(
name, SYSTEM, log_stdout, log_rot_file); 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() { static const oai::logger::printf_logger& pcf_app() {
return oai::logger::logger_registry::get_logger(PCF_APP); return oai::logger::logger_registry::get_logger(PCF_APP);
} }
...@@ -58,4 +60,4 @@ class Logger { ...@@ -58,4 +60,4 @@ class Logger {
static const oai::logger::printf_logger& system() { static const oai::logger::printf_logger& system() {
return oai::logger::logger_registry::get_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