comparison src/event/ngx_event_openssl.c @ 5081:bebcc2f837d3

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.
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 23 Feb 2013 11:54:25 +0000
parents 03513220b83b
children 23a186e8ca45 35b00bcf72fe
comparison
equal deleted inserted replaced
5080:8da37c1b22a4 5081:bebcc2f837d3
1840 goto failed; 1840 goto failed;
1841 } 1841 }
1842 } 1842 }
1843 1843
1844 sess_id = ngx_slab_alloc_locked(shpool, sizeof(ngx_ssl_sess_id_t)); 1844 sess_id = ngx_slab_alloc_locked(shpool, sizeof(ngx_ssl_sess_id_t));
1845
1845 if (sess_id == NULL) { 1846 if (sess_id == NULL) {
1846 goto failed; 1847
1848 /* drop the oldest non-expired session and try once more */
1849
1850 ngx_ssl_expire_sessions(cache, shpool, 0);
1851
1852 sess_id = ngx_slab_alloc_locked(shpool, sizeof(ngx_ssl_sess_id_t));
1853
1854 if (sess_id == NULL) {
1855 goto failed;
1856 }
1847 } 1857 }
1848 1858
1849 #if (NGX_PTR_SIZE == 8) 1859 #if (NGX_PTR_SIZE == 8)
1850 1860
1851 id = sess_id->sess_id; 1861 id = sess_id->sess_id;
1852 1862
1853 #else 1863 #else
1854 1864
1855 id = ngx_slab_alloc_locked(shpool, sess->session_id_length); 1865 id = ngx_slab_alloc_locked(shpool, sess->session_id_length);
1866
1856 if (id == NULL) { 1867 if (id == NULL) {
1857 goto failed; 1868
1869 /* drop the oldest non-expired session and try once more */
1870
1871 ngx_ssl_expire_sessions(cache, shpool, 0);
1872
1873 id = ngx_slab_alloc_locked(shpool, sess->session_id_length);
1874
1875 if (id == NULL) {
1876 goto failed;
1877 }
1858 } 1878 }
1859 1879
1860 #endif 1880 #endif
1861 1881
1862 ngx_memcpy(cached_sess, buf, len); 1882 ngx_memcpy(cached_sess, buf, len);