mosquitto icon indicating copy to clipboard operation
mosquitto copied to clipboard

SSL_Write returns error with SSL_ERROR_SYSCALL and errno=0

Open gopicisco opened this issue 2 years ago • 3 comments

Hi,

Mosquitto client version 2.0.15 Linux - alpine linux aarch64 openssl 1.1.1q

The mosquitto client SSL connection sometimes disconnects with rc=14 and the errno is EPROTO we added a log message in net__handle_ssl as below

-static int net__handle_ssl(struct mosquitto* mosq, int ret)
+static int net__handle_ssl(struct mosquitto* mosq, int ret, bool read)
 {
 	int err;

@@ -955,6 +955,7 @@ static int net__handle_ssl(struct mosquitto* mosq, int ret)
 		errno = EAGAIN;
 	}
 	else {
+		log__printf(mosq, MOSQ_LOG_ERR, "==> Client: %s, SSL_ERROR_SYSCALL, ret: %d, err: %d, errno: %d, is_read: %d", mosq->id, ret, err, errno, read);
 		net__print_ssl_error(mosq);
 		errno = EPROTO;
 	}
@@ -978,7 +979,7 @@ ssize_t net__read(struct mosquitto *mosq, void *buf, size_t count)
 	if(mosq->ssl){
 		ret = SSL_read(mosq->ssl, buf, (int)count);
 		if(ret <= 0){
-			ret = net__handle_ssl(mosq, ret);
+			ret = net__handle_ssl(mosq, ret, true);
 		}
 		return (ssize_t )ret;
 	}else{
@@ -1010,7 +1011,7 @@ ssize_t net__write(struct mosquitto *mosq, const void *buf, size_t count)
 		mosq->want_write = false;
 		ret = SSL_write(mosq->ssl, buf, (int)count);
 		if(ret < 0){
-			ret = net__handle_ssl(mosq, ret);
+			ret = net__handle_ssl(mosq, ret, false);
 		}
 		return (ssize_t )ret;

And the received log print is as below Client: XXXXXXXX, SSL_ERROR_SYSCALL, ret: -1, err: 5, errno: 0, is_read: 0

SSL_Write is returning -1 and SSL_get_error returns 5 (SSL_ERROR_SYSCALL) with errno 0. Unable to understand the reason for this error. Due to this behavior, the mosquitto_loop ends and returns with MOSQ_ERR_ERRNO (14) and doesn't attempt to reconnect. Appreciate your help in debugging the reason for this error

Thanks

gopicisco avatar Mar 07 '23 17:03 gopicisco

This issue is not happening with mosquitto 2.0.14 library. When the above error is seen (SSL_ERROR_SYSCALL with errno=0m SSL_Write), the mosquitto library is not reconnecting.

gopicisco avatar Mar 13 '23 04:03 gopicisco

You may would like to see my comment that I mentioned your issue. It is related to libmosquitto not being able to handle EOF and other non-fatal SSL errors.

rickvargas avatar May 16 '24 20:05 rickvargas