Skip to content

Commit 0f68763

Browse files
committed
bugfix: nginx does not guarentee the parent pointer of the rbtree root is meaningful, which could lead to inifinite loops when ngx_lua tried to abort pending timers prematurely (upon worker exit). thanks pengqi for the patch in #362.
1 parent a2dee0c commit 0f68763

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/ngx_http_lua_timer.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ ngx_http_lua_abort_pending_timers(ngx_event_t *ev)
419419
ngx_int_t i, n;
420420
ngx_event_t **events;
421421
ngx_connection_t *c, *saved_c = NULL;
422-
ngx_rbtree_node_t *cur, *prev, *next, *sentinel;
422+
ngx_rbtree_node_t *cur, *prev, *next, *sentinel, *temp;
423423
ngx_http_lua_timer_ctx_t *tctx;
424424
ngx_http_lua_main_conf_t *lmcf;
425425

@@ -463,7 +463,13 @@ ngx_http_lua_abort_pending_timers(ngx_event_t *ev)
463463
sentinel = ngx_event_timer_rbtree.sentinel;
464464

465465
cur = ngx_event_timer_rbtree.root;
466-
prev = cur->parent;
466+
467+
/* XXX nginx does not guarentee the parent of root is meaningful,
468+
* so we temporarily override it to simplify tree traversal. */
469+
temp = cur->parent;
470+
cur->parent = NULL;
471+
472+
prev = NULL;
467473

468474
events = ngx_pcalloc(ngx_cycle->pool,
469475
lmcf->pending_timers * sizeof(ngx_event_t));
@@ -528,6 +534,9 @@ ngx_http_lua_abort_pending_timers(ngx_event_t *ev)
528534
cur = next;
529535
}
530536

537+
/* restore the old tree root's parent */
538+
ngx_event_timer_rbtree.root->parent = temp;
539+
531540
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
532541
"lua found %i pending timers to be aborted prematurely",
533542
n);

0 commit comments

Comments
 (0)