Skip to content

Commit f87d1f1

Browse files
spacewanderthibaultcha
authored andcommitted
bugfix: ngx.pipe: cleared the pending event after aborting the uthread.
1 parent 86941a7 commit f87d1f1

File tree

1 file changed

+22
-34
lines changed

1 file changed

+22
-34
lines changed

src/ngx_http_lua_pipe.c

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ static void ngx_http_lua_pipe_resume_write_handler(ngx_event_t *ev);
7777
static void ngx_http_lua_pipe_resume_wait_handler(ngx_event_t *ev);
7878
static ngx_int_t ngx_http_lua_pipe_resume(ngx_http_request_t *r);
7979
static void ngx_http_lua_pipe_dummy_event_handler(ngx_event_t *ev);
80-
static void ngx_http_lua_pipe_cleanup_helper(
81-
ngx_http_lua_co_ctx_t *wait_co_ctx);
80+
static void ngx_http_lua_pipe_clear_event(ngx_event_t *ev);
8281
static void ngx_http_lua_pipe_proc_read_stdout_cleanup(void *data);
8382
static void ngx_http_lua_pipe_proc_read_stderr_cleanup(void *data);
8483
static void ngx_http_lua_pipe_proc_write_cleanup(void *data);
@@ -2217,19 +2216,7 @@ ngx_http_lua_pipe_resume_helper(ngx_event_t *ev,
22172216
ev->timedout = 0;
22182217
}
22192218

2220-
if (ev->timer_set) {
2221-
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, 0,
2222-
"lua pipe del timer for ev:%p", ev);
2223-
ngx_del_timer(ev);
2224-
}
2225-
2226-
if (ev->posted) {
2227-
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, 0,
2228-
"lua pipe del posted event for ev:%p", ev);
2229-
ngx_delete_posted_event(ev);
2230-
}
2231-
2232-
ev->handler = ngx_http_lua_pipe_dummy_event_handler;
2219+
ngx_http_lua_pipe_clear_event(ev);
22332220

22342221
r = ngx_http_lua_get_req(wait_co_ctx->co);
22352222
c = r->connection;
@@ -2377,15 +2364,21 @@ ngx_http_lua_pipe_dummy_event_handler(ngx_event_t *ev)
23772364

23782365

23792366
static void
2380-
ngx_http_lua_pipe_cleanup_helper(ngx_http_lua_co_ctx_t *wait_co_ctx)
2367+
ngx_http_lua_pipe_clear_event(ngx_event_t *ev)
23812368
{
2382-
if (wait_co_ctx->sleep.timer_set) {
2383-
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, wait_co_ctx->sleep.log, 0,
2384-
"lua pipe del timer for ev:%p", &wait_co_ctx->sleep);
2385-
ngx_del_timer(&wait_co_ctx->sleep);
2369+
ev->handler = ngx_http_lua_pipe_dummy_event_handler;
2370+
2371+
if (ev->timer_set) {
2372+
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, 0,
2373+
"lua pipe del timer for ev:%p", ev);
2374+
ngx_del_timer(ev);
23862375
}
23872376

2388-
wait_co_ctx->cleanup = NULL;
2377+
if (ev->posted) {
2378+
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, 0,
2379+
"lua pipe del posted event for ev:%p", ev);
2380+
ngx_delete_posted_event(ev);
2381+
}
23892382
}
23902383

23912384

@@ -2404,10 +2397,10 @@ ngx_http_lua_pipe_proc_read_stdout_cleanup(void *data)
24042397
c = proc->pipe->stdout_ctx->c;
24052398
if (c) {
24062399
rev = c->read;
2407-
rev->handler = ngx_http_lua_pipe_dummy_event_handler;
2400+
ngx_http_lua_pipe_clear_event(rev);
24082401
}
24092402

2410-
ngx_http_lua_pipe_cleanup_helper(wait_co_ctx);
2403+
wait_co_ctx->cleanup = NULL;
24112404
}
24122405

24132406

@@ -2426,10 +2419,10 @@ ngx_http_lua_pipe_proc_read_stderr_cleanup(void *data)
24262419
c = proc->pipe->stderr_ctx->c;
24272420
if (c) {
24282421
rev = c->read;
2429-
rev->handler = ngx_http_lua_pipe_dummy_event_handler;
2422+
ngx_http_lua_pipe_clear_event(rev);
24302423
}
24312424

2432-
ngx_http_lua_pipe_cleanup_helper(wait_co_ctx);
2425+
wait_co_ctx->cleanup = NULL;
24332426
}
24342427

24352428

@@ -2448,10 +2441,10 @@ ngx_http_lua_pipe_proc_write_cleanup(void *data)
24482441
c = proc->pipe->stdin_ctx->c;
24492442
if (c) {
24502443
wev = c->write;
2451-
wev->handler = ngx_http_lua_pipe_dummy_event_handler;
2444+
ngx_http_lua_pipe_clear_event(wev);
24522445
}
24532446

2454-
ngx_http_lua_pipe_cleanup_helper(wait_co_ctx);
2447+
wait_co_ctx->cleanup = NULL;
24552448
}
24562449

24572450

@@ -2471,14 +2464,9 @@ ngx_http_lua_pipe_proc_wait_cleanup(void *data)
24712464
pipe_node = (ngx_http_lua_pipe_node_t *) &node->color;
24722465
pipe_node->wait_co_ctx = NULL;
24732466

2474-
if (wait_co_ctx->sleep.posted) {
2475-
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
2476-
"lua pipe del posted event for ev:%p",
2477-
&wait_co_ctx->sleep);
2478-
ngx_delete_posted_event(&wait_co_ctx->sleep);
2479-
}
2467+
ngx_http_lua_pipe_clear_event(&wait_co_ctx->sleep);
24802468

2481-
ngx_http_lua_pipe_cleanup_helper(wait_co_ctx);
2469+
wait_co_ctx->cleanup = NULL;
24822470
}
24832471

24842472

0 commit comments

Comments
 (0)