]> git.kaiwu.me - nginx.git/commitdiff
Allowed up to two EBUSY errors from sendfile().
authorMaxim Dounin <mdounin@mdounin.ru>
Fri, 3 Jan 2014 23:31:58 +0000 (03:31 +0400)
committerMaxim Dounin <mdounin@mdounin.ru>
Fri, 3 Jan 2014 23:31:58 +0000 (03:31 +0400)
Fallback to synchronous sendfile() now only done on 3rd EBUSY without
any progress in a row.  Not falling back is believed to be better
in case of occasional EBUSY, though protection is still needed to
make sure there will be no infinite loop.

src/core/ngx_connection.h
src/http/ngx_http_copy_filter_module.c

index c7b3b315c6296873d8c408b2e23d1e06a5e2a854..05b1ad4ceed666ce984b099e561a6c89b27ffa4a 100644 (file)
@@ -177,6 +177,7 @@ struct ngx_connection_s {
 
 #if (NGX_HAVE_AIO_SENDFILE)
     unsigned            aio_sendfile:1;
+    unsigned            busy_count:2;
     ngx_buf_t          *busy_sendfile;
 #endif
 
index 95bc0b83564e5f7d18711e455cd8b9f7433e0d9c..3ad27b0425b30fb32b2b088febbe57a66ff4bd84 100644 (file)
@@ -169,13 +169,15 @@ ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
             offset = c->busy_sendfile->file_pos;
 
             if (file->aio) {
-                c->aio_sendfile = (offset != file->aio->last_offset);
+                c->busy_count = (offset == file->aio->last_offset) ?
+                                c->busy_count + 1 : 0;
                 file->aio->last_offset = offset;
 
-                if (c->aio_sendfile == 0) {
+                if (c->busy_count > 2) {
                     ngx_log_error(NGX_LOG_ALERT, c->log, 0,
                                   "sendfile(%V) returned busy again",
                                   &file->name);
+                    c->aio_sendfile = 0;
                 }
             }