remove retries from SSL (#14026)
remove retries
Costa Tsaousis committed
Nov 21, 2022 at 00:44 UTC
55c073c253ea57f43caec7779efc72f773c4560c
2 files changed
+20
-25
libnetdata/socket/socket.c
+6
-6
@@ -925,11 +925,11 @@ ssize_t netdata_ssl_read(SSL *ssl, void *buf, size_t num) {
925
926
int bytes, err, retries = 0;
927
928
- do {
928
+ //do {
929
bytes = SSL_read(ssl, buf, (int)num);
930
err = SSL_get_error(ssl, bytes);
931
retries++;
932
- } while (bytes <= 0 && (err == SSL_ERROR_WANT_READ));
932
+ //} while (bytes <= 0 && (err == SSL_ERROR_WANT_READ));
933
934
if(unlikely(bytes <= 0))
935
error("SSL_read() returned %d bytes, SSL error %d", bytes, err);
@@ -946,7 +946,7 @@ ssize_t netdata_ssl_write(SSL *ssl, const void *buf, size_t num) {
946
int bytes, err, retries = 0;
947
size_t total = 0;
948
949
- do {
949
+ //do {
950
bytes = SSL_write(ssl, (uint8_t *)buf + total, (int)(num - total));
951
err = SSL_get_error(ssl, bytes);
952
retries++;
@@ -954,13 +954,13 @@ ssize_t netdata_ssl_write(SSL *ssl, const void *buf, size_t num) {
954
if(bytes > 0)
955
total += bytes;
956
957
- } while ((bytes <= 0 && (err == SSL_ERROR_WANT_WRITE)) || (bytes > 0 && total < num));
957
+ //} while ((bytes <= 0 && (err == SSL_ERROR_WANT_WRITE)) || (bytes > 0 && total < num));
958
959
if(unlikely(bytes <= 0))
960
- error("SSL_read() returned %d bytes, SSL error %d", bytes, err);
960
+ error("SSL_write() returned %d bytes, SSL error %d", bytes, err);
961
962
if(retries > 1)
963
- error_limit(&erl, "SSL_read() retried %d times", retries);
963
+ error_limit(&erl, "SSL_write() retried %d times", retries);
964
965
return bytes;
966
}
web/server/web_client.c
+14
-19
@@ -1212,25 +1212,9 @@ static inline void web_client_send_http_header(struct web_client *w) {
1212
ssize_t bytes;
1213
#ifdef ENABLE_HTTPS
1214
if ( (!web_client_check_unix(w)) && (netdata_ssl_srv_ctx) ) {
1215
- if ( ( w->ssl.conn ) && ( !w->ssl.flags ) ){
1216
- while((bytes = netdata_ssl_write(w->ssl.conn, buffer_tostring(w->response.header_output), buffer_strlen(w->response.header_output))) < 0) {
1217
- count++;
1218
- if(count > 100 || (errno != EAGAIN && errno != EWOULDBLOCK)) {
1219
- error("Cannot send HTTPS headers to web client.");
1220
- break;
1221
- }
1222
- }
1223
- } else {
1224
- while((bytes = send(w->ofd, buffer_tostring(w->response.header_output), buffer_strlen(w->response.header_output), 0)) == -1) {
1225
- count++;
1226
-
1227
- if(count > 100 || (errno != EAGAIN && errno != EWOULDBLOCK)) {
1228
- error("Cannot send HTTP headers to web client.");
1229
- break;
1230
- }
1231
- }
1232
- }
1233
- } else {
1215
+ if ( ( w->ssl.conn ) && ( w->ssl.flags == NETDATA_SSL_HANDSHAKE_COMPLETE ) )
1216
+ bytes = netdata_ssl_write(w->ssl.conn, buffer_tostring(w->response.header_output), buffer_strlen(w->response.header_output));
1217
+ else {
1218
while((bytes = send(w->ofd, buffer_tostring(w->response.header_output), buffer_strlen(w->response.header_output), 0)) == -1) {
1219
count++;
1220
@@ -1239,6 +1223,17 @@ static inline void web_client_send_http_header(struct web_client *w) {
1223
break;
1224
}
1225
}
1226
+ }
1227
+ }
1228
+ else {
1229
+ while((bytes = send(w->ofd, buffer_tostring(w->response.header_output), buffer_strlen(w->response.header_output), 0)) == -1) {
1230
+ count++;
1231
+
1232
+ if(count > 100 || (errno != EAGAIN && errno != EWOULDBLOCK)) {
1233
+ error("Cannot send HTTP headers to web client.");
1234
+ break;
1235
+ }
1236
+ }
1237
}
1238
#else
1239
while((bytes = send(w->ofd, buffer_tostring(w->response.header_output), buffer_strlen(w->response.header_output), 0)) == -1) {