@@ -284,6 +284,8 @@ static SSL_CTX *createSSLContext(serverTLSContextConfig *ctx_config, int protoco
284284    return  NULL ;
285285}
286286
287+ static  long long  lastTlsConfigureTime  =  0LL ;
288+ 
287289/* Attempt to configure/reconfigure TLS. This operation is atomic and will 
288290 * leave the SSL_CTX unchanged if fails. 
289291 * @priv: config of serverTLSContextConfig. 
@@ -296,6 +298,9 @@ static int tlsConfigure(void *priv, int reconfigure) {
296298    SSL_CTX  * ctx  =  NULL ;
297299    SSL_CTX  * client_ctx  =  NULL ;
298300
301+     serverLog (LL_DEBUG , "Configuring TLS" );
302+     lastTlsConfigureTime  =  server .ustime ;
303+ 
299304    if  (!reconfigure  &&  valkey_tls_ctx ) {
300305        return  C_OK ;
301306    }
@@ -419,6 +424,18 @@ static int tlsConfigure(void *priv, int reconfigure) {
419424    return  C_ERR ;
420425}
421426
427+ static  void  tlsReconfigureIfNeeded (void ) {
428+     if  (server .tls_ctx_config .cert_reload_interval_mins  >  0 ) {
429+         const  long long  configAgeMicros  =  server .ustime  -  lastTlsConfigureTime ;
430+         const  long long  configAgeMinutes  =  ((configAgeMicros  / 1000 ) / 1000 ) / 60 ;
431+         if  (configAgeMinutes  >  server .tls_ctx_config .cert_reload_interval_mins ) {
432+             if  (tlsConfigure (& server .tls_ctx_config , 1 ) ==  C_ERR ) {
433+                 serverLog (LL_WARNING , "Unable to update TLS configuration. Check server logs." );
434+             }
435+         }
436+     }
437+ }
438+ 
422439static  ConnectionType  CT_TLS ;
423440
424441/* Normal socket connections have a simple events/handler correlation. 
@@ -465,6 +482,8 @@ static void updateTLSError(tls_connection *conn) {
465482}
466483
467484static  connection  * createTLSConnection (int  client_side ) {
485+     // Reload the cert if needed for new connections 
486+     tlsReconfigureIfNeeded ();
468487    SSL_CTX  * ctx  =  valkey_tls_ctx ;
469488    if  (client_side  &&  valkey_tls_client_ctx ) ctx  =  valkey_tls_client_ctx ;
470489    tls_connection  * conn  =  zcalloc (sizeof (tls_connection ));
0 commit comments