summaryrefslogtreecommitdiff
path: root/src/connection.c
diff options
context:
space:
mode:
authorOzan Tezcan <ozantezcan@gmail.com>2022-09-06 09:04:33 +0300
committerGitHub <noreply@github.com>2022-09-06 09:04:33 +0300
commit3761fdb048e22a5277bd577f87c462dfe019823a (patch)
treef7a2181d08822b48752780c22c1a104b9fffc489 /src/connection.c
parente764e2a627ace62f6081076aead9902d4871ca59 (diff)
downloadredis-3761fdb048e22a5277bd577f87c462dfe019823a.tar.gz
Use cached value correctly inside connectionTypeTls() (#11236)
When Redis is built without TLS support, connectionTypeTls() function keeps searching connection type as cached connection type is NULL. Added another variable to track if we cached the connection type to prevent search after the first time. Noticed a log warning message is printed repeatedly by connectionTypeTls. Co-authored-by: zhenwei pi <pizhenwei@bytedance.com> Co-authored-by: Oran Agra <oran@redislabs.com>
Diffstat (limited to 'src/connection.c')
-rw-r--r--src/connection.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/connection.c b/src/connection.c
index 5a5cd2767..6bb0c9ec1 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -103,11 +103,15 @@ ConnectionType *connectionTypeTcp() {
/* Cache TLS connection type, query it by string once */
ConnectionType *connectionTypeTls() {
static ConnectionType *ct_tls = NULL;
+ static int cached = 0;
- if (ct_tls != NULL)
- return ct_tls;
+ /* Unlike the TCP and Unix connections, the TLS one can be missing
+ * So we need the cached pointer to handle NULL correctly too. */
+ if (!cached) {
+ cached = 1;
+ ct_tls = connectionByType(CONN_TYPE_TLS);
+ }
- ct_tls = connectionByType(CONN_TYPE_TLS);
return ct_tls;
}