Skip to content

Commit 48e4830

Browse files
committed
bugfix: the stream-typed cosocket resolver handler did not handle some special errors correctly.
1 parent c2f4dda commit 48e4830

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

src/ngx_http_lua_socket_tcp.c

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -644,14 +644,14 @@ ngx_http_lua_socket_tcp_connect(lua_State *L)
644644
}
645645

646646
if (u->conn_waiting) {
647-
/* resolved and already connecting */
647+
dd("resolved and already connecting");
648648
return lua_yield(L, 0);
649649
}
650650

651651
n = lua_gettop(L) - saved_top;
652652
if (n) {
653-
/* errors occurred during resolving or connecting
654-
* or already connected */
653+
dd("errors occurred during resolving or connecting"
654+
"or already connected");
655655
return n;
656656
}
657657

@@ -784,19 +784,7 @@ ngx_http_lua_socket_resolve_handler(ngx_resolver_ctx_t *ctx)
784784
}
785785
#endif
786786

787-
if (ur->naddrs == 0) {
788-
ngx_resolve_name_done(ctx);
789-
u->ft_type |= NGX_HTTP_LUA_SOCKET_FT_RESOLVER;
790-
791-
lua_pushnil(L);
792-
lua_pushliteral(L, "name cannot be resolved to a address");
793-
794-
if (waiting) {
795-
ngx_http_run_posted_requests(c);
796-
}
797-
798-
return;
799-
}
787+
ngx_http_lua_assert(ur->naddrs > 0);
800788

801789
if (ur->naddrs == 1) {
802790
i = 0;
@@ -864,9 +852,8 @@ ngx_http_lua_socket_resolve_handler(ngx_resolver_ctx_t *ctx)
864852
ur->host.len = len;
865853
ur->naddrs = 1;
866854

867-
ur->ctx = NULL;
868-
869855
ngx_resolve_name_done(ctx);
856+
ur->ctx = NULL;
870857

871858
u->conn_waiting = 0;
872859
u->write_co_ctx = NULL;
@@ -884,13 +871,17 @@ ngx_http_lua_socket_resolve_handler(ngx_resolver_ctx_t *ctx)
884871

885872
nomem:
886873

887-
ngx_resolve_name_done(ctx);
888-
u->ft_type |= NGX_HTTP_LUA_SOCKET_FT_NOMEM;
874+
if (ur->ctx) {
875+
ngx_resolve_name_done(ctx);
876+
ur->ctx = NULL;
877+
}
889878

890-
lua_pushnil(L);
891-
lua_pushliteral(L, "no memory");
879+
u->write_prepare_retvals = ngx_http_lua_socket_conn_error_retval_handler;
880+
ngx_http_lua_socket_handle_conn_error(r, u,
881+
NGX_HTTP_LUA_SOCKET_FT_NOMEM);
892882

893883
if (waiting) {
884+
dd("run posted requests");
894885
ngx_http_run_posted_requests(c);
895886
}
896887
}
@@ -2518,10 +2509,13 @@ ngx_http_lua_socket_handle_conn_error(ngx_http_request_t *r,
25182509
u->read_event_handler = ngx_http_lua_socket_dummy_handler;
25192510
u->write_event_handler = ngx_http_lua_socket_dummy_handler;
25202511

2512+
dd("connection waiting: %d", (int) u->conn_waiting);
2513+
2514+
coctx = u->write_co_ctx;
2515+
25212516
if (u->conn_waiting) {
25222517
u->conn_waiting = 0;
25232518

2524-
coctx = u->write_co_ctx;
25252519
coctx->cleanup = NULL;
25262520
u->write_co_ctx = NULL;
25272521

@@ -2537,6 +2531,9 @@ ngx_http_lua_socket_handle_conn_error(ngx_http_request_t *r,
25372531
"lua tcp socket waking up the current request");
25382532

25392533
r->write_event_handler(r);
2534+
2535+
} else {
2536+
u->write_prepare_retvals(r, u, coctx->co);
25402537
}
25412538
}
25422539

0 commit comments

Comments
 (0)