]> git.kaiwu.me - nginx.git/commitdiff
SSL: reduced logging of session cache failures (ticket #621).
authorMaxim Dounin <mdounin@mdounin.ru>
Wed, 12 Oct 2022 17:14:36 +0000 (20:14 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Wed, 12 Oct 2022 17:14:36 +0000 (20:14 +0300)
Session cache allocations might fail as long as the new session is different
in size from the one least recently used (and freed when the first allocation
fails).  In particular, it might not be possible to allocate space for
sessions with client certificates, since they are noticeably bigger than
normal sessions.

To ensure such allocation failures won't clutter logs, logging level changed
to "warn", and logging is now limited to at most one warning per second.

src/event/ngx_event_openssl.c
src/event/ngx_event_openssl.h

index a80f30253c28fc3e163ccbba3794420b63a3c45a..5cd0c5bc785f012fde7cadeb6587c7bb44f29532 100644 (file)
@@ -3770,6 +3770,8 @@ ngx_ssl_session_cache_init(ngx_shm_zone_t *shm_zone, void *data)
 
     ngx_queue_init(&cache->expire_queue);
 
+    cache->fail_time = 0;
+
     len = sizeof(" in SSL session shared cache \"\"") + shm_zone->shm.name.len;
 
     shpool->log_ctx = ngx_slab_alloc(shpool, len);
@@ -3953,8 +3955,11 @@ failed:
 
     ngx_shmtx_unlock(&shpool->mutex);
 
-    ngx_log_error(NGX_LOG_ALERT, c->log, 0,
-                  "could not allocate new session%s", shpool->log_ctx);
+    if (cache->fail_time != ngx_time()) {
+        cache->fail_time = ngx_time();
+        ngx_log_error(NGX_LOG_WARN, c->log, 0,
+                      "could not allocate new session%s", shpool->log_ctx);
+    }
 
     return 0;
 }
index c9e86d9c0c899d82ac938f17e6425883e8f0c9cc..4d005ed75a92d431bfefad156d0fc734cc28b261 100644 (file)
@@ -150,6 +150,7 @@ typedef struct {
     ngx_rbtree_t                session_rbtree;
     ngx_rbtree_node_t           sentinel;
     ngx_queue_t                 expire_queue;
+    time_t                      fail_time;
 } ngx_ssl_session_cache_t;