comparison src/event/ngx_event_openssl.c @ 5153:0dbe5eaa2388 stable-1.2

Merge of r5082: SSL: retry "sess_id" and "id" allocations. 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 Fri, 29 Mar 2013 17:17:45 +0000
parents f25d0bbc4392
children
comparison
equal deleted inserted replaced
5152:2ff51c32791f 5153:0dbe5eaa2388
1714 goto failed; 1714 goto failed;
1715 } 1715 }
1716 } 1716 }
1717 1717
1718 sess_id = ngx_slab_alloc_locked(shpool, sizeof(ngx_ssl_sess_id_t)); 1718 sess_id = ngx_slab_alloc_locked(shpool, sizeof(ngx_ssl_sess_id_t));
1719
1719 if (sess_id == NULL) { 1720 if (sess_id == NULL) {
1720 goto failed; 1721
1722 /* drop the oldest non-expired session and try once more */
1723
1724 ngx_ssl_expire_sessions(cache, shpool, 0);
1725
1726 sess_id = ngx_slab_alloc_locked(shpool, sizeof(ngx_ssl_sess_id_t));
1727
1728 if (sess_id == NULL) {
1729 goto failed;
1730 }
1721 } 1731 }
1722 1732
1723 #if (NGX_PTR_SIZE == 8) 1733 #if (NGX_PTR_SIZE == 8)
1724 1734
1725 id = sess_id->sess_id; 1735 id = sess_id->sess_id;
1726 1736
1727 #else 1737 #else
1728 1738
1729 id = ngx_slab_alloc_locked(shpool, sess->session_id_length); 1739 id = ngx_slab_alloc_locked(shpool, sess->session_id_length);
1740
1730 if (id == NULL) { 1741 if (id == NULL) {
1731 goto failed; 1742
1743 /* drop the oldest non-expired session and try once more */
1744
1745 ngx_ssl_expire_sessions(cache, shpool, 0);
1746
1747 id = ngx_slab_alloc_locked(shpool, sess->session_id_length);
1748
1749 if (id == NULL) {
1750 goto failed;
1751 }
1732 } 1752 }
1733 1753
1734 #endif 1754 #endif
1735 1755
1736 ngx_memcpy(cached_sess, buf, len); 1756 ngx_memcpy(cached_sess, buf, len);