-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathnginx-1.12.1-stream.patch
107 lines (89 loc) · 3.48 KB
/
nginx-1.12.1-stream.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
--- a/src/stream/ngx_stream_upstream.h 2018-04-13 19:05:12.456091028 +0800
+++ b/src/stream/ngx_stream_upstream.h 2018-04-13 20:07:45.604186242 +0800
@@ -137,6 +137,7 @@
ngx_stream_upstream_state_t *state;
unsigned connected:1;
unsigned proxy_protocol:1;
+ unsigned blocked:1;
} ngx_stream_upstream_t;
--- a/src/stream/ngx_stream_proxy_module.c 2018-04-12 10:19:21.721098716 +0800
+++ b/src/stream/ngx_stream_proxy_module.c 2018-04-17 14:58:23.554108490 +0800
@@ -61,7 +61,7 @@
ngx_stream_proxy_srv_conf_t *pscf);
static ngx_int_t ngx_stream_proxy_set_local(ngx_stream_session_t *s,
ngx_stream_upstream_t *u, ngx_stream_upstream_local_t *local);
-static void ngx_stream_proxy_connect(ngx_stream_session_t *s);
+void ngx_stream_proxy_connect(ngx_stream_session_t *s);
static void ngx_stream_proxy_init_upstream(ngx_stream_session_t *s);
static void ngx_stream_proxy_resolve_handler(ngx_resolver_ctx_t *ctx);
static void ngx_stream_proxy_upstream_handler(ngx_event_t *ev);
@@ -73,7 +73,7 @@
static void ngx_stream_proxy_process(ngx_stream_session_t *s,
ngx_uint_t from_upstream, ngx_uint_t do_write);
static void ngx_stream_proxy_next_upstream(ngx_stream_session_t *s);
-static void ngx_stream_proxy_finalize(ngx_stream_session_t *s, ngx_uint_t rc);
+void ngx_stream_proxy_finalize(ngx_stream_session_t *s, ngx_uint_t rc);
static u_char *ngx_stream_proxy_log_error(ngx_log_t *log, u_char *buf,
size_t len);
@@ -646,7 +646,7 @@
}
-static void
+void
ngx_stream_proxy_connect(ngx_stream_session_t *s)
{
ngx_int_t rc;
@@ -662,29 +662,35 @@
u = s->upstream;
- u->connected = 0;
- u->proxy_protocol = pscf->proxy_protocol;
+ if (!u->blocked) {
+ u->connected = 0;
+ u->proxy_protocol = pscf->proxy_protocol;
- if (u->state) {
- u->state->response_time = ngx_current_msec - u->state->response_time;
- }
+ if (u->state) {
+ u->state->response_time = ngx_current_msec - u->state->response_time;
+ }
- u->state = ngx_array_push(s->upstream_states);
- if (u->state == NULL) {
- ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
- return;
- }
+ u->state = ngx_array_push(s->upstream_states);
+ if (u->state == NULL) {
+ ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
+ return;
+ }
- ngx_memzero(u->state, sizeof(ngx_stream_upstream_state_t));
+ ngx_memzero(u->state, sizeof(ngx_stream_upstream_state_t));
- u->state->connect_time = (ngx_msec_t) -1;
- u->state->first_byte_time = (ngx_msec_t) -1;
- u->state->response_time = ngx_current_msec;
+ u->state->connect_time = (ngx_msec_t) -1;
+ u->state->first_byte_time = (ngx_msec_t) -1;
+ u->state->response_time = ngx_current_msec;
+ }
rc = ngx_event_connect_peer(&u->peer);
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, "proxy connect: %i", rc);
+ if (rc == NGX_BLOCK) {
+ return;
+ }
+
if (rc == NGX_ERROR) {
ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
return;
@@ -1663,7 +1669,7 @@
}
-static void
+void
ngx_stream_proxy_next_upstream(ngx_stream_session_t *s)
{
ngx_msec_t timeout;
@@ -1729,7 +1735,7 @@
}
-static void
+void
ngx_stream_proxy_finalize(ngx_stream_session_t *s, ngx_uint_t rc)
{
ngx_connection_t *pc;