forked from cfsego/nginx-limit-upstream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx.patch
113 lines (95 loc) · 3.98 KB
/
nginx.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
Index: /branches/nginx/src/core/ngx_core.h
===================================================================
--- /branches/nginx/src/core/ngx_core.h (revision 3473)
+++ /branches/nginx/src/core/ngx_core.h (working copy)
@@ -33,6 +33,7 @@
#define NGX_DONE -4
#define NGX_DECLINED -5
#define NGX_ABORT -6
+#define NGX_BLOCK -7
#include <ngx_errno.h>
Index: /branches/nginx/src/http/ngx_http_upstream.h
===================================================================
--- /branches/nginx/src/http/ngx_http_upstream.h (revision 3473)
+++ /branches/nginx/src/http/ngx_http_upstream.h (working copy)
@@ -320,6 +320,7 @@
unsigned request_sent:1;
unsigned header_sent:1;
+ unsigned blocked:1;
};
@@ -341,6 +342,8 @@
ngx_int_t ngx_http_upstream_hide_headers_hash(ngx_conf_t *cf,
ngx_http_upstream_conf_t *conf, ngx_http_upstream_conf_t *prev,
ngx_str_t *default_hide_headers, ngx_hash_init_t *hash);
+void ngx_http_upstream_connect(ngx_http_request_t *r,
+ ngx_http_upstream_t *u);
#define ngx_http_conf_upstream_srv_conf(uscf, module) \
Index: /branches/nginx/src/http/ngx_http_upstream.c
===================================================================
--- /branches/nginx/src/http/ngx_http_upstream.c (revision 3473)
+++ /branches/nginx/src/http/ngx_http_upstream.c (working copy)
@@ -24,8 +24,6 @@
static void ngx_http_upstream_wr_check_broken_connection(ngx_http_request_t *r);
static void ngx_http_upstream_check_broken_connection(ngx_http_request_t *r,
ngx_event_t *ev);
-static void ngx_http_upstream_connect(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
static ngx_int_t ngx_http_upstream_reinit(ngx_http_request_t *r,
ngx_http_upstream_t *u);
static void ngx_http_upstream_send_request(ngx_http_request_t *r,
@@ -1070,41 +1068,48 @@
}
-static void
+void
ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
{
ngx_int_t rc;
ngx_time_t *tp;
ngx_connection_t *c;
- r->connection->log->action = "connecting to upstream";
+ if (!u->blocked) {
- r->connection->single_connection = 0;
+ r->connection->log->action = "connecting to upstream";
- if (u->state && u->state->response_sec) {
- tp = ngx_timeofday();
- u->state->response_sec = tp->sec - u->state->response_sec;
- u->state->response_msec = tp->msec - u->state->response_msec;
- }
+ r->connection->single_connection = 0;
- u->state = ngx_array_push(r->upstream_states);
- if (u->state == NULL) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
+ if (u->state && u->state->response_sec) {
+ tp = ngx_timeofday();
+ u->state->response_sec = tp->sec - u->state->response_sec;
+ u->state->response_msec = tp->msec - u->state->response_msec;
+ }
- ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t));
+ u->state = ngx_array_push(r->upstream_states);
+ if (u->state == NULL) {
+ ngx_http_upstream_finalize_request(r, u,
+ NGX_HTTP_INTERNAL_SERVER_ERROR);
+ return;
+ }
- tp = ngx_timeofday();
- u->state->response_sec = tp->sec;
- u->state->response_msec = tp->msec;
+ ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t));
+
+ tp = ngx_timeofday();
+ u->state->response_sec = tp->sec;
+ u->state->response_msec = tp->msec;
+ }
rc = ngx_event_connect_peer(&u->peer);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http upstream connect: %i", rc);
+ if (rc == NGX_BLOCK) {
+ return;
+ }
+
if (rc == NGX_ERROR) {
ngx_http_upstream_finalize_request(r, u,
NGX_HTTP_INTERNAL_SERVER_ERROR);