-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the HTTP server shutdown logic to respond correctly to Ctrl+C and stop commands #1517
Open
mdemoret-nv
wants to merge
5
commits into
nv-morpheus:branch-24.06
Choose a base branch
from
mdemoret-nv:mdd_improve-http-shutdown
base: branch-24.06
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b381084
Catch and log exceptions occurring while executing a langchain agent …
dagardner-nv 04f1217
Improving the shutdown process for HTTP source stage
mdemoret-nv 684c68f
Merge branch 'branch-24.03' into mdd_improve-http-shutdown
mdemoret-nv dd9c4a3
Updating the openai service
mdemoret-nv 11622b0
Merge remote-tracking branch 'upstream/branch-24.03' into mdd_improve…
mdemoret-nv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,11 @@ | |
|
||
#pragma once | ||
|
||
#include <boost/asio/io_context.hpp> // for io_context | ||
#include <boost/asio/ip/tcp.hpp> // for tcp, tcp::acceptor, tcp::endpoint, tcp::socket | ||
#include <boost/beast/core/error.hpp> // for error_code | ||
#include <boost/asio/io_context.hpp> // for io_context | ||
#include <boost/asio/ip/tcp.hpp> // for tcp, tcp::acceptor, tcp::endpoint, tcp::socket | ||
#include <boost/beast/core/error.hpp> // for error_code | ||
#include <boost/beast/http/message.hpp> | ||
#include <boost/beast/http/string_body.hpp> | ||
#include <boost/beast/http/verb.hpp> // for verb | ||
#include <boost/system/error_code.hpp> // for error_code | ||
#include <pybind11/pytypes.h> // for pybind11::function | ||
|
@@ -68,7 +70,9 @@ using parse_status_t = std::tuple<unsigned /*http status code*/, | |
* Refer to https://www.boost.org/doc/libs/1_74_0/libs/system/doc/html/system.html#ref_class_error_code for more | ||
* information regarding `boost::system::error_code`. | ||
*/ | ||
using payload_parse_fn_t = std::function<parse_status_t(const std::string& /* post body */)>; | ||
using payload_parse_fn_t = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the docstring to reflect the change here |
||
std::function<parse_status_t(const boost::asio::ip::tcp::endpoint& endpoint, | ||
const boost::beast::http::request<boost::beast::http::string_body> request)>; | ||
|
||
constexpr std::size_t DefaultMaxPayloadSize{1024 * 1024 * 10}; // 10MB | ||
|
||
|
@@ -104,9 +108,13 @@ class HttpServer | |
void stop(); | ||
bool is_running() const; | ||
|
||
size_t run_one(); | ||
|
||
private: | ||
void start_listener(std::binary_semaphore& listener_semaphore, std::binary_semaphore& started_semaphore); | ||
|
||
mutable std::mutex m_mutex; | ||
|
||
std::string m_bind_address; | ||
unsigned short m_port; | ||
std::string m_endpoint; | ||
|
@@ -117,7 +125,7 @@ class HttpServer | |
std::vector<std::thread> m_listener_threads; | ||
boost::asio::io_context m_io_context; | ||
std::shared_ptr<Listener> m_listener; | ||
std::shared_ptr<payload_parse_fn_t> m_payload_parse_fn; | ||
payload_parse_fn_t m_payload_parse_fn; | ||
std::atomic<bool> m_is_running; | ||
}; | ||
|
||
|
@@ -130,7 +138,7 @@ class Listener : public std::enable_shared_from_this<Listener> | |
{ | ||
public: | ||
Listener(boost::asio::io_context& io_context, | ||
std::shared_ptr<morpheus::payload_parse_fn_t> payload_parse_fn, | ||
morpheus::payload_parse_fn_t payload_parse_fn, | ||
const std::string& bind_address, | ||
unsigned short port, | ||
const std::string& endpoint, | ||
|
@@ -140,7 +148,7 @@ class Listener : public std::enable_shared_from_this<Listener> | |
|
||
~Listener() = default; | ||
|
||
void run(); | ||
void start(); | ||
void stop(); | ||
bool is_running() const; | ||
|
||
|
@@ -152,7 +160,7 @@ class Listener : public std::enable_shared_from_this<Listener> | |
boost::asio::ip::tcp::endpoint m_tcp_endpoint; | ||
std::unique_ptr<boost::asio::ip::tcp::acceptor> m_acceptor; | ||
|
||
std::shared_ptr<morpheus::payload_parse_fn_t> m_payload_parse_fn; | ||
morpheus::payload_parse_fn_t m_payload_parse_fn; | ||
const std::string& m_url_endpoint; | ||
boost::beast::http::verb m_method; | ||
std::size_t m_max_payload_size; | ||
|
@@ -177,6 +185,7 @@ struct HttpServerInterfaceProxy | |
static void start(HttpServer& self); | ||
static void stop(HttpServer& self); | ||
static bool is_running(const HttpServer& self); | ||
static size_t run_one(HttpServer& self); | ||
|
||
// Context manager methods | ||
static HttpServer& enter(HttpServer& self); | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we aren't completely on
ControlMessage
yet, can we make the output message a template choice?