Skip to content
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

Fix warnings in tcp/udp UT #2744

Open
wants to merge 12 commits into
base: devel
Choose a base branch
from
8 changes: 7 additions & 1 deletion Drv/Ip/IpSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,14 @@ SocketIpStatus IpSocket::recv(NATIVE_INT_TYPE fd, U8* data, U32& req_read) {
for (U32 i = 0; (i < SOCKET_MAX_ITERATIONS) && (size <= 0); i++) {
// Attempt to recv out data
size = this->recvProtocol(fd, data, req_read);

LeStarch marked this conversation as resolved.
Show resolved Hide resolved
// Nothing to be received
if ((size == -1) && (errno == EAGAIN)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JohanBertrand @csmith608 this file's changes should be kept, as they improve error handling (
EAGAIN is differentiated from EINTR).

req_read = 0;
return SOCK_SUCCESS;
}
// Error is EINTR, just try again
if (size == -1 && ((errno == EINTR) || errno == EAGAIN)) {
if ((size == -1) && (errno == EINTR)) {
continue;
}
// Zero bytes read reset or bad ef means we've disconnected
Expand Down
12 changes: 6 additions & 6 deletions Drv/Ip/SocketComponentHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ void SocketComponentHelper::readTask(void* pointer) {
status = self->reconnect();
if(status != SOCK_SUCCESS) {
Fw::Logger::log(
"[WARNING] Failed to open port with status %lu and errno %lu\n",
static_cast<POINTER_CAST>(status),
static_cast<POINTER_CAST>(errno));
"[WARNING] Failed to open port with status %d and errno %d\n",
status,
errno);
(void) Os::Task::delay(SOCKET_RETRY_INTERVAL);
continue;
}
Expand All @@ -182,9 +182,9 @@ void SocketComponentHelper::readTask(void* pointer) {
// recv blocks, so it may have been a while since its done an isOpened check
status = self->recv(data, size);
if ((status != SOCK_SUCCESS) && (status != SOCK_INTERRUPTED_TRY_AGAIN)) {
Fw::Logger::log("[WARNING] Failed to recv from port with status %lu and errno %lu\n",
static_cast<POINTER_CAST>(status),
static_cast<POINTER_CAST>(errno));
Fw::Logger::log("[WARNING] Failed to recv from port with status %d and errno %d\n",
status,
errno);
self->close();
buffer.setSize(0);
} else {
Expand Down
2 changes: 1 addition & 1 deletion Drv/Ip/SocketComponentHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class SocketComponentHelper {
* \return true if socket is open, false otherwise
*/
bool isOpened();

/**
* \brief Re-open port if it has been disconnected
*
Expand Down
2 changes: 1 addition & 1 deletion Drv/TcpClient/test/ut/TcpClientTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void TcpClientTester ::test_with_loop(U32 iterations, bool recv_thread) {
}
}
// Properly stop the client on the last iteration
if ((1 + i) == iterations && recv_thread) {
if (((1 + i) == iterations) && recv_thread) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JohanBertrand @csmith608 keep, code clean-up

this->component.stop();
this->component.join();
} else {
Expand Down
7 changes: 3 additions & 4 deletions Drv/TcpServer/test/ut/TcpServerTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,15 @@ void TcpServerTester ::test_with_loop(U32 iterations, bool recv_thread) {
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JohanBertrand @csmith608 Review with upcoming change.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears I already changed where this occurs in my latest changes, although I can't remember exactly why. https://github.com/nasa/fprime/blob/devel/Drv/TcpServer/test/ut/TcpServerTester.cpp#L91-L103

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the position of client.close() in the last commit, after updating the branch with the changes from devel.

From what I have seen in my different tests, if client.close() is called before this->component.close();, there are some cases where ::accept(serverFd, nullptr, nullptr); in Drv/Ip/TcpServerSocket.cpp (See: https://github.com/nasa/fprime/blob/devel/Drv/Ip/TcpServerSocket.cpp#L110) will hang forever.

It usually happened about once every 1600 CI runs.

I just ran the UT for 100.000 times on my machine with the changes in this PR, without failures on the CI, timeouts or hang.

// Properly stop the client on the last iteration
if ((1 + i) == iterations && recv_thread) {
this->component.shutdown();
Copy link
Contributor Author

@JohanBertrand JohanBertrand Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LeStarch Can you confirm that we do not need this shutdown, since it's already part of the stop function?

Keeping it is causing a timeout on my setup (when the UT is tasking more than 1s)

if (((1 + i) == iterations) && recv_thread) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JohanBertrand @csmith608 keep, code clean-up

this->component.stop();
client.close(client_fd); // Client must be closed first or the server risks binding to an existing address
this->component.close();
client.close(client_fd); // Client must be closed first or the server risks binding to an existing address
this->component.shutdown();
this->component.join();
} else {
client.close(client_fd); // Client must be closed first or the server risks binding to an existing address
this->component.close();
client.close(client_fd); // Client must be closed first or the server risks binding to an existing address
}
}
ASSERT_from_ready_SIZE(iterations);
Expand Down
2 changes: 1 addition & 1 deletion Drv/Udp/test/ut/UdpTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void UdpTester::test_with_loop(U32 iterations, bool recv_thread) {
}
}
// Properly stop the client on the last iteration
if ((1 + i) == iterations && recv_thread) {
if (((1 + i) == iterations) && recv_thread) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JohanBertrand @csmith608 keep, code clean-up

this->component.stop();
this->component.join();
} else {
Expand Down
Loading