diff options
author | Maxim Dounin <mdounin@mdounin.ru> | 2013-02-23 11:54:25 +0000 |
---|---|---|
committer | Maxim Dounin <mdounin@mdounin.ru> | 2013-02-23 11:54:25 +0000 |
commit | 890ee444cafb9dcce387bd0814c2996a60ecf10e (patch) | |
tree | 971fb9d2d3d47a77603ab94915ecd4827125625d | |
parent | 56bc5f250bd99fe41f12b9a6b859ce5788a363f1 (diff) | |
download | nginx-890ee444cafb9dcce387bd0814c2996a60ecf10e.tar.gz nginx-890ee444cafb9dcce387bd0814c2996a60ecf10e.zip |
SSL: retry "sess_id" and "id" allocations.
In case of fully populated SSL session cache with no memory left for
new allocations, ngx_ssl_new_session() will try to expire the oldest
non-expired session and retry, but only in case when slab allocation
fails for "cached_sess", not when slab allocation fails for either
"sess_id" or "id", which can happen for number of reasons and results
in new session not being cached.
Patch fixes this by adding retry logic to "sess_id" & "id" allocations.
Patch by Piotr Sikora.
-rw-r--r-- | src/event/ngx_event_openssl.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c index b8f1cae91..62ce12c14 100644 --- a/src/event/ngx_event_openssl.c +++ b/src/event/ngx_event_openssl.c @@ -1842,8 +1842,18 @@ ngx_ssl_new_session(ngx_ssl_conn_t *ssl_conn, ngx_ssl_session_t *sess) } sess_id = ngx_slab_alloc_locked(shpool, sizeof(ngx_ssl_sess_id_t)); + if (sess_id == NULL) { - goto failed; + + /* drop the oldest non-expired session and try once more */ + + ngx_ssl_expire_sessions(cache, shpool, 0); + + sess_id = ngx_slab_alloc_locked(shpool, sizeof(ngx_ssl_sess_id_t)); + + if (sess_id == NULL) { + goto failed; + } } #if (NGX_PTR_SIZE == 8) @@ -1853,8 +1863,18 @@ ngx_ssl_new_session(ngx_ssl_conn_t *ssl_conn, ngx_ssl_session_t *sess) #else id = ngx_slab_alloc_locked(shpool, sess->session_id_length); + if (id == NULL) { - goto failed; + + /* drop the oldest non-expired session and try once more */ + + ngx_ssl_expire_sessions(cache, shpool, 0); + + id = ngx_slab_alloc_locked(shpool, sess->session_id_length); + + if (id == NULL) { + goto failed; + } } #endif |