Closed pereyra-m closed 2 months ago
I begin with the RCA to identify all the required changes.
It was found that easy handler is never removed from the multi handler, so after the first execute()
, it'll always fail.
I continue with the MULTI handler class fix, testing the normal and the timeout request.
I continue working on the pre-existent error with the MULTI handler. I'm analyzing the results of the adress-sanitizer report.
```
root@6f68a3e7a4f3:/workspaces/wazuh-http-request/build/test/component# ./urlrequest_component_test --gtest_filter=*Multi*
Note: Google Test filter = *Multi*
[==========] Running 12 tests from 2 test suites.
[----------] Global test environment set-up.
[----------] 10 tests from ComponentTestInterface
[ RUN ] ComponentTestInterface.DownloadFileUsingTheMultiHandler
curlHandlerInit: 1
cURLMultiHandler created: 1
curlWrapper after Init: 1
cURLMultiHandler::execute() started: 1
[ OK ] ComponentTestInterface.DownloadFileUsingTheMultiHandler (3 ms)
[ RUN ] ComponentTestInterface.InterruptMultiHandler
/workspaces/wazuh-http-request/test/component/component_test.cpp:261: Skipped
This test is skipped because it is not working properly.
[ SKIPPED ] ComponentTestInterface.InterruptMultiHandler (0 ms)
[ RUN ] ComponentTestInterface.DownloadFileEmptyURLUsingTheMultiHandler
/workspaces/wazuh-http-request/test/component/component_test.cpp:316: Skipped
This test is skipped because it is not working properly.
[ SKIPPED ] ComponentTestInterface.DownloadFileEmptyURLUsingTheMultiHandler (0 ms)
[ RUN ] ComponentTestInterface.DownloadFileErrorUsingTheMultiHandler
/workspaces/wazuh-http-request/test/component/component_test.cpp:341: Skipped
This test is skipped because it is not working properly.
[ SKIPPED ] ComponentTestInterface.DownloadFileErrorUsingTheMultiHandler (0 ms)
[ RUN ] ComponentTestInterface.DownloadTestTimeoutMultiHandler
Test the DOWNLOAD request with timeout for MULTI handler: 1
curlHandlerInit: 1
curlWrapper after Init: 1
=================================================================
==2151==ERROR: AddressSanitizer: heap-use-after-free on address 0x603000007221 at pc 0x55ea814baf83 bp 0x7ffc8c0fa730 sp 0x7ffc8c0fa720
READ of size 1 at 0x603000007221 thread T0
#0 0x55ea814baf82 in std::__atomic_base
Changes due to review.
This issue depends on https://github.com/wazuh/wazuh-http-request/issues/61
Rebase and unblock
Description
During the testing of #61, it was found that the internal handler is added to the multi-handler in each execution https://github.com/wazuh/wazuh-http-request/blob/314f6edc5c5e44af63c19135bfa7f704ee9cdfe2/src/curlMultiHandler.hpp#L71
Resulting in the following failed test
Details
```c++ TEST_F(ComponentTestInterface, DownloadTestTimeoutMultiHandler) { std::atomic shouldRun {true};
EXPECT_NO_THROW({
HTTPRequest::instance().download(
HttpURL("http://localhost:44441"),
"./test1.txt",
[](auto a, auto) { std::cout << a << std::endl; },
{},
{},
{},
CurlHandlerTypeEnum::MULTI,
shouldRun);
});
EXPECT_NO_THROW({
HTTPRequest::instance().download(
HttpURL("http://localhost:44441"),
"./test2.txt",
[](auto a, auto) { std::cout << a << std::endl; },
{},
{},
{},
CurlHandlerTypeEnum::MULTI,
shouldRun);
});
std::ifstream file1("./test1.txt");
std::string line1;
std::getline(file1, line1);
EXPECT_EQ(line1, "Hello World!");
std::ifstream file2("./test2.txt");
std::string line2;
std::getline(file2, line2);
EXPECT_EQ(line2, "Hello World!");
}
```
```
oot@6f68a3e7a4f3:/workspaces/wazuh-temp/main/build# ./test/component/urlrequest_component_test --gtest_filter=*DownloadTestTimeoutMultiHandler*
Note: Google Test filter = *DownloadTestTimeoutMultiHandler*
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from ComponentTestInterface
[ RUN ] ComponentTestInterface.DownloadTestTimeoutMultiHandler
cURLMultiHandler::execute() failed: curl_multi_add_handle: The easy handle is already added to a multi handle
/workspaces/wazuh-temp/main/test/component/component_test.cpp:1099: Failure
Expected equality of these values:
line2
Which is: ""
"Hello World!"
[ FAILED ] ComponentTestInterface.DownloadTestTimeoutMultiHandler (2 ms)
[----------] 1 test from ComponentTestInterface (2 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (4 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] ComponentTestInterface.DownloadTestTimeoutMultiHandler
1 FAILED TEST
```
**Note**: the following line was modified to add more detail in the error
https://github.com/wazuh/wazuh-http-request/blob/314f6edc5c5e44af63c19135bfa7f704ee9cdfe2/src/curlMultiHandler.hpp#L75
```c++
throw std::runtime_error("cURLMultiHandler::execute() failed: curl_multi_add_handle: " +
std::string(curl_multi_strerror(multiCode)));
```
DoD