Mercurial > hg > nginx-quic
annotate src/core/ngx_open_file_cache.h @ 7152:3b635e8fd499
FastCGI: adjust buffer position when parsing incomplete records.
Previously, nginx failed to move buffer position when parsing an incomplete
record header, and due to this wasn't be able to continue parsing once
remaining bytes of the record header were received.
This can affect response header parsing, potentially generating spurious errors
like "upstream sent unexpected FastCGI request id high byte: 1 while reading
response header from upstream". While this is very unlikely, since usually
record headers are written in a single buffer, this still can happen in real
life, for example, if a record header will be split across two TCP packets
and the second packet will be delayed.
This does not affect non-buffered response body proxying, due to "buf->pos =
buf->last;" at the start of the ngx_http_fastcgi_non_buffered_filter()
function. Also this does not affect buffered response body proxying, as
each input buffer is only passed to the filter once.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 09 Nov 2017 15:35:20 +0300 |
parents | 47ece8818978 |
children |
rev | line source |
---|---|
1453 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4412 | 4 * Copyright (C) Nginx, Inc. |
1453 | 5 */ |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 | |
11 | |
12 #ifndef _NGX_OPEN_FILE_CACHE_H_INCLUDED_ | |
13 #define _NGX_OPEN_FILE_CACHE_H_INCLUDED_ | |
14 | |
15 | |
2277 | 16 #define NGX_OPEN_FILE_DIRECTIO_OFF NGX_MAX_OFF_T_VALUE |
17 | |
18 | |
1453 | 19 typedef struct { |
20 ngx_fd_t fd; | |
21 ngx_file_uniq_t uniq; | |
22 time_t mtime; | |
23 off_t size; | |
3899
e7cd13b7f759
Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents:
3178
diff
changeset
|
24 off_t fs_size; |
2129 | 25 off_t directio; |
3178 | 26 size_t read_ahead; |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2277
diff
changeset
|
27 |
1453 | 28 ngx_err_t err; |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2277
diff
changeset
|
29 char *failed; |
1453 | 30 |
1767
c42431762903
open_file_cache_retest > open_file_cache_valid
Igor Sysoev <igor@sysoev.ru>
parents:
1765
diff
changeset
|
31 time_t valid; |
1453 | 32 |
1772 | 33 ngx_uint_t min_uses; |
34 | |
4477
7033faf6dc3c
Added disable_symlinks directive.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
35 #if (NGX_HAVE_OPENAT) |
4493
47ece8818978
Disable symlinks: added the "from" parameter support to the open file cache.
Valentin Bartenev <vbart@nginx.com>
parents:
4477
diff
changeset
|
36 size_t disable_symlinks_from; |
4477
7033faf6dc3c
Added disable_symlinks directive.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
37 unsigned disable_symlinks:2; |
7033faf6dc3c
Added disable_symlinks directive.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
38 #endif |
7033faf6dc3c
Added disable_symlinks directive.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
39 |
1453 | 40 unsigned test_dir:1; |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2277
diff
changeset
|
41 unsigned test_only:1; |
2072 | 42 unsigned log:1; |
1453 | 43 unsigned errors:1; |
1457 | 44 unsigned events:1; |
1453 | 45 |
46 unsigned is_dir:1; | |
47 unsigned is_file:1; | |
48 unsigned is_link:1; | |
49 unsigned is_exec:1; | |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
50 unsigned is_directio:1; |
1453 | 51 } ngx_open_file_info_t; |
52 | |
53 | |
54 typedef struct ngx_cached_open_file_s ngx_cached_open_file_t; | |
55 | |
56 struct ngx_cached_open_file_s { | |
57 ngx_rbtree_node_t node; | |
1765 | 58 ngx_queue_t queue; |
1453 | 59 |
60 u_char *name; | |
61 time_t created; | |
62 time_t accessed; | |
63 | |
64 ngx_fd_t fd; | |
65 ngx_file_uniq_t uniq; | |
66 time_t mtime; | |
67 off_t size; | |
68 ngx_err_t err; | |
69 | |
1772 | 70 uint32_t uses; |
71 | |
4477
7033faf6dc3c
Added disable_symlinks directive.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
72 #if (NGX_HAVE_OPENAT) |
4493
47ece8818978
Disable symlinks: added the "from" parameter support to the open file cache.
Valentin Bartenev <vbart@nginx.com>
parents:
4477
diff
changeset
|
73 size_t disable_symlinks_from; |
4477
7033faf6dc3c
Added disable_symlinks directive.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
74 unsigned disable_symlinks:2; |
7033faf6dc3c
Added disable_symlinks directive.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
75 #endif |
7033faf6dc3c
Added disable_symlinks directive.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
76 |
1453 | 77 unsigned count:24; |
78 unsigned close:1; | |
1775 | 79 unsigned use_event:1; |
1453 | 80 |
81 unsigned is_dir:1; | |
82 unsigned is_file:1; | |
83 unsigned is_link:1; | |
84 unsigned is_exec:1; | |
2246
987831d73bd8
cache directio flag in open file cache
Igor Sysoev <igor@sysoev.ru>
parents:
2231
diff
changeset
|
85 unsigned is_directio:1; |
1453 | 86 |
87 ngx_event_t *event; | |
88 }; | |
89 | |
90 | |
91 typedef struct { | |
92 ngx_rbtree_t rbtree; | |
1761 | 93 ngx_rbtree_node_t sentinel; |
1765 | 94 ngx_queue_t expire_queue; |
1453 | 95 |
96 ngx_uint_t current; | |
97 ngx_uint_t max; | |
98 time_t inactive; | |
99 } ngx_open_file_cache_t; | |
100 | |
101 | |
102 typedef struct { | |
103 ngx_open_file_cache_t *cache; | |
104 ngx_cached_open_file_t *file; | |
1772 | 105 ngx_uint_t min_uses; |
1453 | 106 ngx_log_t *log; |
107 } ngx_open_file_cache_cleanup_t; | |
108 | |
109 | |
110 typedef struct { | |
111 | |
112 /* ngx_connection_t stub to allow use c->fd as event ident */ | |
113 void *data; | |
114 ngx_event_t *read; | |
115 ngx_event_t *write; | |
116 ngx_fd_t fd; | |
117 | |
118 ngx_cached_open_file_t *file; | |
119 ngx_open_file_cache_t *cache; | |
120 } ngx_open_file_cache_event_t; | |
121 | |
122 | |
123 ngx_open_file_cache_t *ngx_open_file_cache_init(ngx_pool_t *pool, | |
124 ngx_uint_t max, time_t inactive); | |
125 ngx_int_t ngx_open_cached_file(ngx_open_file_cache_t *cache, ngx_str_t *name, | |
126 ngx_open_file_info_t *of, ngx_pool_t *pool); | |
127 | |
128 | |
129 #endif /* _NGX_OPEN_FILE_CACHE_H_INCLUDED_ */ |