Skip to content

Commit c85b35f

Browse files
committed
fixed a segment fault bug with upstream check module when check timeout is longer than the check interval
1 parent 13f5e20 commit c85b35f

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

ngx_http_upstream_check_handler.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,10 @@ ngx_http_check_begin_handler(ngx_event_t *event)
335335

336336
ngx_add_timer(event, ucscf->check_interval/2);
337337

338-
/* This process is processing the event now. */
339-
if (peer->shm->owner == ngx_pid) {
340-
return;
341-
}
338+
/* This process is processing this peer now. */
339+
if ((peer->shm->owner == ngx_pid) ||
340+
(peer->pc.connection != NULL) ||
341+
(peer->check_timeout_ev.timer_set)) {
342342

343343
interval = ngx_current_msec - peer->shm->access_time;
344344
ngx_log_debug5(NGX_LOG_DEBUG_HTTP, event->log, 0,
@@ -1223,11 +1223,14 @@ ngx_http_check_clean_event(ngx_http_check_peer_t *peer)
12231223

12241224
c = peer->pc.connection;
12251225

1226-
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
1227-
"http check clean event: index:%ui, fd: %d",
1228-
peer->index, c->fd);
1226+
if (c) {
1227+
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
1228+
"http check clean event: index:%ui, fd: %d",
1229+
peer->index, c->fd);
12291230

1230-
ngx_close_connection(c);
1231+
ngx_close_connection(c);
1232+
peer->pc.connection = NULL;
1233+
}
12311234

12321235
if (peer->check_timeout_ev.timer_set) {
12331236
ngx_del_timer(&peer->check_timeout_ev);
@@ -1314,7 +1317,10 @@ ngx_http_check_clear_all_events()
13141317
/* Be careful, The shared memory may have been freed after reload */
13151318
if (peer[i].check_timeout_ev.timer_set) {
13161319
c = peer[i].pc.connection;
1317-
ngx_close_connection(c);
1320+
if (c) {
1321+
ngx_close_connection(c);
1322+
peer[i].pc.connection = NULL;
1323+
}
13181324
ngx_del_timer(&peer[i].check_timeout_ev);
13191325
}
13201326

0 commit comments

Comments
 (0)