comparison src/event/ngx_event_openssl.c @ 2280:6453161bf53e

always use buffer, if connection is buffered, this fixes OpenSSL "bad write retry" error, when *) nginx passed a single buf greater than our buffer (say 32K) to OpenSSL, *) OpenSSL returns SSL_ERROR_WANT_WRITE, *) after some time nginx has to send a new data, *) so there are at least two bufs nginx does pass them directly to OpenSSL, *) but copies the first buf part to buffer, and sends the buffer to OpenSSL. *) because the data length is lesser than it was in previous SSL_write(): 16K < 32K, OpenSSL returns SSL_R_BAD_WRITE_RETRY.
author Igor Sysoev <igor@sysoev.ru>
date Thu, 23 Oct 2008 05:58:10 +0000
parents cbf6f2eb57ad
children 31fafd8e7436
comparison
equal deleted inserted replaced
2279:bbb17a60ec44 2280:6453161bf53e
186 186
187 if (ngx_ssl_protocols[protocols >> 1] != 0) { 187 if (ngx_ssl_protocols[protocols >> 1] != 0) {
188 SSL_CTX_set_options(ssl->ctx, ngx_ssl_protocols[protocols >> 1]); 188 SSL_CTX_set_options(ssl->ctx, ngx_ssl_protocols[protocols >> 1]);
189 } 189 }
190 190
191 /*
192 * we need this option because in ngx_ssl_send_chain()
193 * we may switch to a buffered write and may copy leftover part of
194 * previously unbuffered data to our internal buffer
195 */
196 SSL_CTX_set_mode(ssl->ctx, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
197
198 SSL_CTX_set_read_ahead(ssl->ctx, 1); 191 SSL_CTX_set_read_ahead(ssl->ctx, 1);
199 192
200 return NGX_OK; 193 return NGX_OK;
201 } 194 }
202 195
858 int n; 851 int n;
859 ngx_uint_t flush; 852 ngx_uint_t flush;
860 ssize_t send, size; 853 ssize_t send, size;
861 ngx_buf_t *buf; 854 ngx_buf_t *buf;
862 855
863 if (!c->ssl->buffer 856 if (!c->ssl->buffer) {
864 || (in && in->next == NULL && !(c->buffered & NGX_SSL_BUFFERED)))
865 {
866 /*
867 * we avoid a buffer copy if
868 * we do not need to buffer the output
869 * or the incoming buf is a single and our buffer is empty
870 */
871 857
872 while (in) { 858 while (in) {
873 if (ngx_buf_special(in->buf)) { 859 if (ngx_buf_special(in->buf)) {
874 in = in->next; 860 in = in->next;
875 continue; 861 continue;