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

SSL_Write returns error with SSL_ERROR_SYSCALL and errno=0 #2767

Open
gopicisco opened this issue Mar 7, 2023 · 2 comments
Open

SSL_Write returns error with SSL_ERROR_SYSCALL and errno=0 #2767

gopicisco opened this issue Mar 7, 2023 · 2 comments

Comments

@gopicisco
Copy link

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
Copy link
Author

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.

@rickvargas
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants