-
Notifications
You must be signed in to change notification settings - Fork 23
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 error handling in network functions #157
Open
4 tasks done
Labels
Comments
TomasTurina
added
level/task
Task issue
type/enhancement
Enhancement issue
module/agent
phase/feature complete
labels
Sep 13, 2024
Update
|
1 task
1 task
3 tasks
Draft
3 tasks
Draft
3 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
As part of the development of the communicator component of the new agent, we chose to use boost asio/beast as our networking library, which also works with C++20 coroutines.
The first implementation is missing to check for many network errors that can occur during communication. Currently, any failure is not reported correctly and no recovery attempt is made, so we need to improve error handling.
Tasks to be done:
Errors reported during testing
When performing manual tests for other developments we have already encountered some cases that we have to solve:
Handle jwt exceptions
In the following line
if (const auto decoded = jwt::decode<jwt::traits::nlohmann_json>(*m_token); decoded.has_payload_claim("exp"))
a case occurred where a token was returned with an invalid jwt format and the co-routine that handled this task crashed, causing no further attempt to obtain the token and no errors were logged.
Chrash when getting reference from null object
In the following line
return nlohmann::json::parse(boost::beast::buffers_to_string(res.body().data())).at("token").get_ref<const std::string&>();
if the json object has a different format than expected causing “token” to not be where you are looking for it, it causes the crash when trying to do the get_ref() since the at() above would fail.
Example of response that produces the crash:
End of co-routines in case of write/read failure
In Co_PerformHttpRequest when a failure occurs during AsyncWrite/AsyncRead the co_routine is being terminated completely, the correct operation of this should be:
but do not stop the co-routine.
Timeouts in operations with sockets
Timeouts must be added to all socket operations that can block the process/co_routine indefinitely. For example Connect, Write and Read.
The text was updated successfully, but these errors were encountered: