Skip to content

Commit 3d4b839

Browse files
committed
Fix segfault on connection error
1 parent 3825e30 commit 3d4b839

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/ngx_http_redirectionio_module.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ static char *ngx_http_redirectionio_merge_conf(ngx_conf_t *cf, void *parent, voi
431431
RIO_MIN_CONNECTIONS,
432432
RIO_KEEP_CONNECTIONS,
433433
RIO_MAX_CONNECTIONS,
434-
RIO_TIMEOUT,
434+
RIO_DEFAULT_TIMEOUT,
435435
conf,
436436
ngx_http_redirectionio_pool_construct,
437437
ngx_http_redirectionio_pool_destruct
@@ -448,7 +448,7 @@ static char *ngx_http_redirectionio_merge_conf(ngx_conf_t *cf, void *parent, voi
448448
RIO_MIN_CONNECTIONS,
449449
RIO_KEEP_CONNECTIONS,
450450
RIO_MAX_CONNECTIONS,
451-
RIO_TIMEOUT,
451+
RIO_DEFAULT_TIMEOUT,
452452
conf,
453453
ngx_http_redirectionio_pool_construct,
454454
ngx_http_redirectionio_pool_destruct
@@ -507,7 +507,7 @@ static void ngx_http_redirectionio_write_match_action_handler(ngx_event_t *wev)
507507
r = c->data;
508508
ctx = ngx_http_get_module_ctx(r, ngx_http_redirectionio_module);
509509

510-
ngx_add_timer(c->read, RIO_TIMEOUT);
510+
ngx_add_timer(c->read, RIO_DEFAULT_TIMEOUT);
511511
ctx->read_handler = ngx_http_redirectionio_read_match_action_handler;
512512

513513
ngx_http_redirectionio_protocol_send_match(c, r, ctx, &ctx->project_key);

src/ngx_http_redirectionio_module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#define RIO_MIN_CONNECTIONS 0
1616
#define RIO_KEEP_CONNECTIONS 10
1717
#define RIO_MAX_CONNECTIONS 10
18-
#define RIO_TIMEOUT 100
18+
#define RIO_DEFAULT_TIMEOUT 100
1919

2020
#define API_NOT_CALLED 0
2121
#define API_WAITING 1

src/ngx_http_redirectionio_module_pool.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,12 @@ void ngx_http_redirectionio_read_handler(ngx_event_t *rev) {
165165

166166
if (rev->timedout) {
167167
ctx->connection_error = 1;
168-
ctx->read_handler(rev, NULL);
169168
ctx->resource->peer.connection->read->handler = ngx_http_redirectionio_dummy_handler;
170169

171170
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "[redirectionio] connection timeout while reading, skipping module for this request");
172171

172+
ctx->read_handler(rev, NULL);
173+
173174
return;
174175
}
175176

@@ -179,7 +180,6 @@ void ngx_http_redirectionio_read_handler(ngx_event_t *rev) {
179180

180181
if (rv != NGX_OK) {
181182
ctx->connection_error = 1;
182-
ctx->read_handler(rev, NULL);
183183
ctx->resource->peer.connection->read->handler = ngx_http_redirectionio_dummy_handler;
184184

185185
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "[redirectionio] connection error while reading length, skipping module for this request");
@@ -188,6 +188,8 @@ void ngx_http_redirectionio_read_handler(ngx_event_t *rev) {
188188
ngx_del_timer(rev);
189189
}
190190

191+
ctx->read_handler(rev, NULL);
192+
191193
return;
192194
}
193195

@@ -202,13 +204,14 @@ void ngx_http_redirectionio_read_handler(ngx_event_t *rev) {
202204

203205
if (rv != NGX_OK) {
204206
ctx->connection_error = 1;
205-
ctx->read_handler(rev, NULL);
206207
ctx->resource->peer.connection->read->handler = ngx_http_redirectionio_dummy_handler;
207208

208209
if (rev->timer_set) {
209210
ngx_del_timer(rev);
210211
}
211212

213+
ctx->read_handler(rev, NULL);
214+
212215
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "[redirectionio] connection error while reading string: %d, skipping module for this request", rv);
213216

214217
return;

0 commit comments

Comments
 (0)