Closed nilshenrich closed 1 year ago
This issue occurs only for TLS connections.
TCP:
TLS:
What makes it pass:
This issue has nothing to do with sending a message.\ The issue comes up if the client is closed immediately after its start()-method returned
The pipe error is thrown 2 times:
SSL_accept
in TlsServer::connectionInitSSL_shutdown
in TlsServer::connectionDeinitPossible solution: Non-blocking sockets.\ Answer from ChatGPT:
#include <sys/select.h>
#include <unistd.h>
void ssl_accept_thread(SSL* ssl, int sockfd) {
// Set the socket to non-blocking mode.
int flags = fcntl(sockfd, F_GETFL, 0);
fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
// Use select to monitor the socket and ensure that it stays open while SSL_accept is being executed.
while (true) {
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(sockfd, &readfds);
int ret = select(sockfd + 1, &readfds, nullptr, nullptr, nullptr);
if (ret < 0) {
// An error occurred. You can handle the error here or throw an exception.
break;
}
if (FD_ISSET(sockfd, &readfds)) {
// The socket is ready to be read from. Execute SSL_accept.
int ret = SSL_accept(ssl);
if (ret <= 0) {
int error = SSL_get_error(ssl, ret);
if (error == SSL_ERROR_SYSCALL) {
// The socket was closed from the outside. You can ignore the error here
// or print a message if needed.
} else if (error == SSL_ERROR_SSL) {
// Another error occurred. You can handle the error here or throw an exception.
}
break;
}
}
}
}
Non-blocking won't fix this issue. This is caused by already connected sockets closed before initialized. Non-blocking would make no difference
Vorschlag von ChatGPT: MSG_NOSIGNAL setzen
Vorschlag von ChatGPT: MSG_NOSIGNAL setzen
Or set SO_NOSIGPIPE?
Vorschlag von ChatGPT: MSG_NOSIGNAL setzen
Or set SO_NOSIGPIPE?
No, it's Apple only
Not treated as an issue
When a client stops immediately after the start() method returned, the server program throws a pipe error.