Skip to content

Commit 58f916f

Browse files
committed
bugfix: the datagram-typed cosocket resolver handler did not handle some special errors correctly.
1 parent 2cc788b commit 58f916f

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

src/ngx_http_lua_socket_udp.c

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,8 @@ ngx_http_lua_socket_resolve_handler(ngx_resolver_ctx_t *ctx)
468468
lua_concat(L, 2);
469469

470470
#if 1
471-
ur->ctx = NULL;
472471
ngx_resolve_name_done(ctx);
472+
ur->ctx = NULL;
473473
#endif
474474

475475
u->prepare_retvals = ngx_http_lua_socket_error_retval_handler;
@@ -521,19 +521,7 @@ ngx_http_lua_socket_resolve_handler(ngx_resolver_ctx_t *ctx)
521521
}
522522
#endif
523523

524-
if (ur->naddrs == 0) {
525-
ngx_resolve_name_done(ctx);
526-
u->ft_type |= NGX_HTTP_LUA_SOCKET_FT_RESOLVER;
527-
528-
lua_pushnil(L);
529-
lua_pushliteral(L, "name cannot be resolved to a address");
530-
531-
if (waiting) {
532-
ngx_http_run_posted_requests(c);
533-
}
534-
535-
return;
536-
}
524+
ngx_http_lua_assert(ur->naddrs > 0);
537525

538526
if (ur->naddrs == 1) {
539527
i = 0;
@@ -601,9 +589,8 @@ ngx_http_lua_socket_resolve_handler(ngx_resolver_ctx_t *ctx)
601589
ur->host.len = len;
602590
ur->naddrs = 1;
603591

604-
ur->ctx = NULL;
605-
606592
ngx_resolve_name_done(ctx);
593+
ur->ctx = NULL;
607594

608595
u->waiting = 0;
609596

@@ -620,14 +607,21 @@ ngx_http_lua_socket_resolve_handler(ngx_resolver_ctx_t *ctx)
620607

621608
nomem:
622609

623-
ngx_resolve_name_done(ctx);
624-
u->ft_type |= NGX_HTTP_LUA_SOCKET_FT_NOMEM;
610+
if (ur->ctx) {
611+
ngx_resolve_name_done(ctx);
612+
ur->ctx = NULL;
613+
}
625614

626-
lua_pushnil(L);
627-
lua_pushliteral(L, "no memory");
615+
u->prepare_retvals = ngx_http_lua_socket_error_retval_handler;
616+
ngx_http_lua_socket_udp_handle_error(r, u,
617+
NGX_HTTP_LUA_SOCKET_FT_NOMEM);
628618

629619
if (waiting) {
630620
ngx_http_run_posted_requests(c);
621+
622+
} else {
623+
lua_pushnil(L);
624+
lua_pushliteral(L, "no memory");
631625
}
632626
}
633627

@@ -1229,6 +1223,7 @@ ngx_http_lua_socket_udp_handle_error(ngx_http_request_t *r,
12291223
ngx_http_lua_socket_udp_upstream_t *u, ngx_uint_t ft_type)
12301224
{
12311225
ngx_http_lua_ctx_t *ctx;
1226+
ngx_http_lua_co_ctx_t *coctx;
12321227

12331228
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
12341229
"lua udp socket handle error");
@@ -1241,8 +1236,10 @@ ngx_http_lua_socket_udp_handle_error(ngx_http_request_t *r,
12411236

12421237
u->read_event_handler = ngx_http_lua_socket_dummy_handler;
12431238

1244-
if (u->co_ctx) {
1245-
u->co_ctx->cleanup = NULL;
1239+
coctx = u->co_ctx;
1240+
1241+
if (coctx) {
1242+
coctx->cleanup = NULL;
12461243
}
12471244

12481245
if (u->waiting) {
@@ -1254,7 +1251,7 @@ ngx_http_lua_socket_udp_handle_error(ngx_http_request_t *r,
12541251
}
12551252

12561253
ctx->resume_handler = ngx_http_lua_socket_udp_resume;
1257-
ctx->cur_co_ctx = u->co_ctx;
1254+
ctx->cur_co_ctx = coctx;
12581255

12591256
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
12601257
"lua udp socket waking up the current request");

0 commit comments

Comments
 (0)