nilshenrich / TCP_ServerClient

C++ library providing an asynchronous TCP server and client. Additionally, the TCP connection can be TLS encrypted and two-way authenticated.
MIT License
0 stars 0 forks source link

Test execution gets stuck after starting TLS server #4

Open nilshenrich opened 1 week ago

nilshenrich commented 1 week ago

In some gtest executions, the runtime gets stuck right after starting TLS server, see: Unittest_stuck

nilshenrich commented 1 week ago

There is no CPU load and the memory usage doesn't grow

nilshenrich commented 1 week ago

The test execution gets stuck in TlsClient::start method

nilshenrich commented 1 week ago

The test execution gets stuck in TlsClient::start method

Stuck at TlsClient::connectionInit method

nilshenrich commented 1 week ago

The test execution gets stuck in TlsClient::start method

Stuck at TlsClient::connectionInit method

Stuck at TLS handshake: SSL_connect

nilshenrich commented 1 week ago

Possible solution: timeout to don't get stuck infinitely. ChatGPT generated solution:

struct timeval timeout;
timeout.tv_sec = 5;  // Timeout in seconds
timeout.tv_usec = 0;

setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout));
nilshenrich commented 1 week ago

Possible solution: timeout to don't get stuck infinitely. ChatGPT generated solution:

struct timeval timeout;
timeout.tv_sec = 5;  // Timeout in seconds
timeout.tv_usec = 0;

setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout));

No, SO_RCVTIMEO and SO_SNDTIMEO just define the timeout for sending/receiving data on TCP socket

nilshenrich commented 1 week ago

Solution could be:

  1. Start a timeout counter in background just before calling SSL_connect. If timeout has passed without SSL_connect having returned, abort it by freeing the TLS socket: SSL_free
  2. Use non-blocking mode just for connecting and keep trying until timeout has passed