diff --git a/src/common/lua/ngx_wasm_lua.c b/src/common/lua/ngx_wasm_lua.c index 09bd77631..db90b4cb5 100644 --- a/src/common/lua/ngx_wasm_lua.c +++ b/src/common/lua/ngx_wasm_lua.c @@ -331,7 +331,9 @@ thread_handle_rc(ngx_wasm_lua_ctx_t *lctx, ngx_int_t rc) ngx_queue_remove(&lctx->q); if (lctx->error_handler) { - (void) lctx->error_handler(lctx); + /* error_handler can override the rc (e.g. lua resolver errors + * are ignored by the request flow */ + rc = lctx->error_handler(lctx); } } diff --git a/src/common/lua/ngx_wasm_lua_resolver.c b/src/common/lua/ngx_wasm_lua_resolver.c index a71600853..31c1a36b8 100644 --- a/src/common/lua/ngx_wasm_lua_resolver.c +++ b/src/common/lua/ngx_wasm_lua_resolver.c @@ -104,13 +104,13 @@ ngx_wasm_lua_resolver_error_handler(ngx_wasm_lua_ctx_t *lctx) rslv_ctx->state = NGX_WASM_LUA_RESOLVE_ERR; rslv_ctx->handler(rslv_ctx); - } - /* if error before yielding, we already freed the thread */ + return NGX_OK; + } dd("exit"); - return NGX_OK; + return NGX_ERROR; } diff --git a/src/common/ngx_wasm_socket_tcp.c b/src/common/ngx_wasm_socket_tcp.c index 3f69d9103..837bc86a8 100644 --- a/src/common/ngx_wasm_socket_tcp.c +++ b/src/common/ngx_wasm_socket_tcp.c @@ -72,13 +72,10 @@ ngx_wasm_socket_tcp_err(ngx_wasm_socket_tcp_t *sock, } -static void +static ngx_int_t ngx_wasm_socket_tcp_resume(ngx_wasm_socket_tcp_t *sock) { -#if (NGX_WASM_HTTP) - ngx_int_t rc; - ngx_http_wasm_req_ctx_t *rctx; -#endif + ngx_int_t rc = NGX_ERROR; ngx_log_debug0(NGX_LOG_DEBUG_WASM, sock->log, 0, "wasm tcp socket resuming"); @@ -86,31 +83,26 @@ ngx_wasm_socket_tcp_resume(ngx_wasm_socket_tcp_t *sock) switch (sock->env->subsys->kind) { #if (NGX_WASM_HTTP) case NGX_WASM_SUBSYS_HTTP: - rctx = sock->env->ctx.rctx; - rc = sock->resume_handler(sock); /* handle sock event */ - - dd("sock->resume rc: %ld", rc); - - switch (rc) { - case NGX_AGAIN: - ngx_wasm_yield(&rctx->env); - break; - case NGX_ERROR: + { + rc = sock->resume_handler(sock); +#if 0 + /* make HTTP dispatch calls failures produce HTTP 500 */ + if (rc == NGX_ERROR) { ngx_wasm_error(&rctx->env); - break; - default: - ngx_wa_assert(rc == NGX_OK); - ngx_wasm_continue(&rctx->env); - break; } +#endif - ngx_http_wasm_resume(rctx, 1, 1); /* continue request */ break; + } #endif default: ngx_wasm_bad_subsystem(sock->env); break; } + + dd("sock->resume_handler rc: %ld", rc); + + return rc; } @@ -521,7 +513,15 @@ ngx_wasm_socket_resolve_handler(ngx_resolver_ctx_t *ctx) ngx_resolve_name_done(ctx); - ngx_wasm_socket_tcp_resume(sock); + (void) ngx_wasm_socket_tcp_resume(sock); + +#if (NGX_WASM_LUA) + if (ctx->state != NGX_WASM_LUA_RESOLVE_ERR) { + ngx_wasm_resume(sock->env); /* continue request */ + } +#endif + + dd("exit"); } @@ -652,8 +652,8 @@ ngx_wasm_socket_tcp_ssl_handshake(ngx_wasm_socket_tcp_t *sock) static void ngx_wasm_socket_tcp_ssl_handshake_handler(ngx_connection_t *c) { - ngx_wasm_socket_tcp_t *sock; ngx_int_t rc; + ngx_wasm_socket_tcp_t *sock; sock = c->data; @@ -671,7 +671,12 @@ ngx_wasm_socket_tcp_ssl_handshake_handler(ngx_connection_t *c) resume: - ngx_wasm_socket_tcp_resume(sock); + rc = ngx_wasm_socket_tcp_resume(sock); + if (rc != NGX_AGAIN) { + ngx_wasm_resume(sock->env); /* continue request */ + } + + dd("exit"); } @@ -1355,8 +1360,10 @@ ngx_wasm_socket_tcp_finalize_write(ngx_wasm_socket_tcp_t *sock) static void ngx_wasm_socket_tcp_handler(ngx_event_t *ev) { + ngx_int_t rc; ngx_connection_t *c = ev->data; ngx_wasm_socket_tcp_t *sock = c->data; + ngx_wasm_subsys_env_t *env = sock->env; ngx_log_debug1(NGX_LOG_DEBUG_WASM, ev->log, 0, "wasm tcp socket handler (wev: %d)", @@ -1375,7 +1382,10 @@ ngx_wasm_socket_tcp_handler(ngx_event_t *ev) sock->read_event_handler(sock); } - ngx_wasm_socket_tcp_resume(sock); + rc = ngx_wasm_socket_tcp_resume(sock); + if (rc != NGX_AGAIN) { + ngx_wasm_resume(env); /* continue request */ + } dd("exit"); } diff --git a/src/common/ngx_wasm_subsystem.c b/src/common/ngx_wasm_subsystem.c index c4c65f6ca..0ff532ff6 100644 --- a/src/common/ngx_wasm_subsystem.c +++ b/src/common/ngx_wasm_subsystem.c @@ -36,3 +36,18 @@ ngx_wasm_set_resume_handler(ngx_wasm_subsys_env_t *env) } #endif } + + +ngx_inline void +ngx_wasm_resume(ngx_wasm_subsys_env_t *env) +{ +#if (NGX_WASM_HTTP) + ngx_http_wasm_req_ctx_t *rctx; + + if (env->subsys->kind == NGX_WASM_SUBSYS_HTTP) { + rctx = env->ctx.rctx; + + ngx_http_wasm_resume(rctx); + } +#endif +} diff --git a/src/common/ngx_wasm_subsystem.h b/src/common/ngx_wasm_subsystem.h index 7f016ee10..eb1739bb1 100644 --- a/src/common/ngx_wasm_subsystem.h +++ b/src/common/ngx_wasm_subsystem.h @@ -35,6 +35,7 @@ ngx_wasm_phase_t *ngx_wasm_phase_lookup(ngx_wasm_subsystem_t *subsys, ngx_uint_t phaseidx); void ngx_wasm_set_resume_handler(ngx_wasm_subsys_env_t *env); +void ngx_wasm_resume(ngx_wasm_subsys_env_t *env); #endif /* _NGX_WASM_SUBSYSTEM_H_INCLUDED_ */ diff --git a/src/common/proxy_wasm/ngx_proxy_wasm_host.c b/src/common/proxy_wasm/ngx_proxy_wasm_host.c index d3d48ee26..590116251 100644 --- a/src/common/proxy_wasm/ngx_proxy_wasm_host.c +++ b/src/common/proxy_wasm/ngx_proxy_wasm_host.c @@ -1030,7 +1030,7 @@ static ngx_int_t ngx_proxy_wasm_hfuncs_send_local_response(ngx_wavm_instance_t *instance, wasm_val_t args[], wasm_val_t rets[]) { - int32_t status, reason_len, body_len, cl; + int32_t status, reason_len, body_len; #if (NGX_DEBUG) int32_t grpc_status; #endif @@ -1067,7 +1067,6 @@ ngx_proxy_wasm_hfuncs_send_local_response(ngx_wavm_instance_t *instance, if (rctx->entered_header_filter && !rctx->entered_body_filter) { r = rctx->r; - cl = body_len; s.data = body; s.len = body_len; @@ -1078,8 +1077,6 @@ ngx_proxy_wasm_hfuncs_send_local_response(ngx_wavm_instance_t *instance, if (body_len) { /* append linefeed */ - cl++; - rc = ngx_wasm_chain_append(r->connection->pool, &rctx->resp_chunk, body_len, &lf, &rctx->free_bufs, rctx->env.buf_tag, 0); @@ -1089,7 +1086,6 @@ ngx_proxy_wasm_hfuncs_send_local_response(ngx_wavm_instance_t *instance, } ngx_http_wasm_set_resp_status(rctx, status, reason, reason_len); - ngx_http_wasm_set_resp_content_length(r, cl); rctx->resp_chunk_override = 1; diff --git a/src/http/ngx_http_wasm.h b/src/http/ngx_http_wasm.h index e18b58af5..94a1dff8b 100644 --- a/src/http/ngx_http_wasm.h +++ b/src/http/ngx_http_wasm.h @@ -164,8 +164,7 @@ ngx_int_t ngx_http_wasm_prepend_resp_body(ngx_http_wasm_req_ctx_t *rctx, /* resume handler */ void ngx_http_wasm_set_resume_handler(ngx_http_wasm_req_ctx_t *rctx); -void ngx_http_wasm_resume(ngx_http_wasm_req_ctx_t *rctx, unsigned main, - unsigned wev); +void ngx_http_wasm_resume(ngx_http_wasm_req_ctx_t *rctx); /* externs */ diff --git a/src/http/ngx_http_wasm_filter_module.c b/src/http/ngx_http_wasm_filter_module.c index e62168e06..ff32f62a0 100644 --- a/src/http/ngx_http_wasm_filter_module.c +++ b/src/http/ngx_http_wasm_filter_module.c @@ -101,7 +101,7 @@ ngx_http_wasm_header_filter_handler(ngx_http_request_t *r) rc = ngx_http_next_header_filter(r); goto done; - } else if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) { + } else if (rc == NGX_ERROR) { if (rc == NGX_ERROR) { rc = NGX_HTTP_INTERNAL_SERVER_ERROR; goto done; @@ -110,6 +110,8 @@ ngx_http_wasm_header_filter_handler(ngx_http_request_t *r) if (rctx->resp_content_chosen) { goto done; } + + ngx_wa_assert(0); } #if (NGX_DEBUG) else if (rc == NGX_AGAIN) { @@ -121,6 +123,12 @@ ngx_http_wasm_header_filter_handler(ngx_http_request_t *r) "wasm \"header_filter\" ops resume rc: %d " "(resp_chunk_override: %d)", rc, rctx->resp_chunk_override); + + } else { + /* ignore */ + ngx_wa_assert(rc == NGX_OK + || rc == NGX_DECLINED + || rc >= NGX_HTTP_SPECIAL_RESPONSE); } #endif diff --git a/src/http/ngx_http_wasm_module.c b/src/http/ngx_http_wasm_module.c index 86d3e5e1a..44c95d062 100644 --- a/src/http/ngx_http_wasm_module.c +++ b/src/http/ngx_http_wasm_module.c @@ -765,6 +765,7 @@ ngx_http_wasm_rewrite_handler(ngx_http_request_t *r) break; default: ngx_wa_assert(rc == NGX_ERROR); + rc = NGX_HTTP_INTERNAL_SERVER_ERROR; goto done; } } @@ -985,6 +986,10 @@ ngx_http_wasm_content(ngx_http_wasm_req_ctx_t *rctx) } rc = ngx_wasm_ops_resume(&rctx->opctx, NGX_HTTP_CONTENT_PHASE); + if (rctx->env.state == NGX_WASM_STATE_ERROR) { + rc = NGX_HTTP_INTERNAL_SERVER_ERROR; + } + dd("content ops resume rc: %ld", rc); rc = ngx_http_wasm_check_finalize(rctx, rc); if (rc == NGX_ERROR @@ -1022,8 +1027,6 @@ ngx_http_wasm_content(ngx_http_wasm_req_ctx_t *rctx) ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "wasm running orig \"content\" handler"); - rctx->resp_content_chosen = 1; - rc = rctx->r_content_handler(r); } else if (r->header_sent || rctx->resp_content_sent) { @@ -1197,7 +1200,7 @@ ngx_http_wasm_wev_handler(ngx_http_request_t *r) if (rc == NGX_OK || rc == NGX_DONE) { if (r == r->main) { r->write_event_handler = ngx_http_core_run_phases; - ngx_http_wasm_resume(rctx, r == r->main, 1); + ngx_http_wasm_resume(rctx); return; } @@ -1250,34 +1253,21 @@ ngx_http_wasm_set_resume_handler(ngx_http_wasm_req_ctx_t *rctx) void -ngx_http_wasm_resume(ngx_http_wasm_req_ctx_t *rctx, unsigned main, unsigned wev) +ngx_http_wasm_resume(ngx_http_wasm_req_ctx_t *rctx) { ngx_http_request_t *r = rctx->r; ngx_connection_t *c = r->connection; dd("enter"); - ngx_wa_assert(wev); - if (ngx_wasm_yielding(&rctx->env)) { dd("yielding"); return; } - if (main) { - if (wev) { - dd("resuming request wev..."); - r->write_event_handler(r); - dd("...done resuming request wev"); - } -#if 0 - else { - dd("resuming request rev..."); - r->read_event_handler(r); - dd("...done resuming request"); - } -#endif - } + dd("resuming request wev..."); + r->write_event_handler(r); + dd("...done resuming request wev"); dd("running posted requests..."); ngx_http_run_posted_requests(c); diff --git a/src/http/proxy_wasm/ngx_http_proxy_wasm.c b/src/http/proxy_wasm/ngx_http_proxy_wasm.c index 1e5d22e57..00bd9a7c6 100644 --- a/src/http/proxy_wasm/ngx_http_proxy_wasm.c +++ b/src/http/proxy_wasm/ngx_http_proxy_wasm.c @@ -144,6 +144,9 @@ ngx_http_proxy_wasm_on_request_body_handler(ngx_http_request_t *r) NGX_PROXY_WASM_STEP_REQ_BODY); if (rc == NGX_AGAIN) { ngx_wasm_yield(&rctx->env); + + } else if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) { + ngx_wasm_error(&rctx->env); } } diff --git a/src/http/proxy_wasm/ngx_http_proxy_wasm_dispatch.c b/src/http/proxy_wasm/ngx_http_proxy_wasm_dispatch.c index 34c3172f0..dddd54aed 100644 --- a/src/http/proxy_wasm/ngx_http_proxy_wasm_dispatch.c +++ b/src/http/proxy_wasm/ngx_http_proxy_wasm_dispatch.c @@ -317,7 +317,7 @@ ngx_http_proxy_wasm_dispatch(ngx_proxy_wasm_exec_t *pwexec, */ #if (NGX_DEBUG) elt->key.data[0] = ngx_toupper(elt->key.data[0]); - ngx_log_debug1(NGX_LOG_DEBUG_ALL, r->connection->log, 0, + ngx_log_debug1(NGX_LOG_DEBUG_WASM, r->connection->log, 0, "proxy_wasm http dispatch cannot override the " "\"%V\" header, skipping", &elt->key); #endif @@ -468,8 +468,9 @@ ngx_http_proxy_wasm_dispatch_handler(ngx_event_t *ev) sock->data = call; rc = sock->resume_handler(sock); - if (rc == NGX_ERROR) { - ngx_http_wasm_resume(rctx, 1, 1); + dd("sock->resume rc: %ld", rc); + if (rc != NGX_AGAIN) { + ngx_http_wasm_resume(rctx); } } @@ -711,7 +712,7 @@ ngx_http_proxy_wasm_dispatch_resume_handler(ngx_wasm_socket_tcp_t *sock) ngx_proxy_wasm_exec_t *pwexec = call->pwexec; ngx_proxy_wasm_filter_t *filter = pwexec->filter; ngx_proxy_wasm_err_e ecode = NGX_PROXY_WASM_ERR_NONE; - ngx_proxy_wasm_step_e step; + ngx_proxy_wasm_step_e step = pwexec->parent->step; dd("enter"); @@ -725,7 +726,7 @@ ngx_http_proxy_wasm_dispatch_resume_handler(ngx_wasm_socket_tcp_t *sock) case NGX_HTTP_PROXY_WASM_DISPATCH_START: - ngx_log_debug0(NGX_LOG_DEBUG_ALL, sock->log, 0, + ngx_log_debug0(NGX_LOG_DEBUG_WASM, sock->log, 0, "proxy_wasm http dispatch connecting..."); call->state = NGX_HTTP_PROXY_WASM_DISPATCH_CONNECTING; @@ -759,7 +760,7 @@ ngx_http_proxy_wasm_dispatch_resume_handler(ngx_wasm_socket_tcp_t *sock) goto error; } - ngx_log_debug0(NGX_LOG_DEBUG_ALL, sock->log, 0, + ngx_log_debug0(NGX_LOG_DEBUG_WASM, sock->log, 0, "proxy_wasm http dispatch sending request..."); rc = ngx_wasm_socket_tcp_send(sock, nl); @@ -847,6 +848,8 @@ ngx_http_proxy_wasm_dispatch_resume_handler(ngx_wasm_socket_tcp_t *sock) ecode = ngx_proxy_wasm_run_step(pwexec, NGX_PROXY_WASM_STEP_DISPATCH_RESPONSE); if (ecode != NGX_PROXY_WASM_ERR_NONE) { + /* catch trap for tcp socket resume retval */ + rc = NGX_ERROR; goto error2; } @@ -856,36 +859,7 @@ ngx_http_proxy_wasm_dispatch_resume_handler(ngx_wasm_socket_tcp_t *sock) /* remove current call now that callback was invoked */ pwexec->call = NULL; - if (ngx_proxy_wasm_dispatch_calls_total(pwexec)) { - ngx_log_debug0(NGX_LOG_DEBUG_ALL, pwexec->log, 0, - "proxy_wasm more http dispatch calls pending..."); - - ngx_proxy_wasm_ctx_set_next_action(pwexec->parent, - NGX_PROXY_WASM_ACTION_PAUSE); - - } else { - ngx_log_debug0(NGX_LOG_DEBUG_ALL, pwexec->log, 0, - "proxy_wasm last http dispatch call handled"); - - ngx_proxy_wasm_ctx_set_next_action(pwexec->parent, - NGX_PROXY_WASM_ACTION_CONTINUE); - } - - if (pwexec->parent->action == NGX_PROXY_WASM_ACTION_CONTINUE) { - /* resume current step if unfinished */ - rc = ngx_proxy_wasm_resume(pwexec->parent, pwexec->parent->phase, - step); - if (rc != NGX_OK && rc != NGX_AGAIN) { - goto error2; - } - - } else if (pwexec->parent->action == NGX_PROXY_WASM_ACTION_PAUSE) { - rc = NGX_AGAIN; - } - ngx_http_proxy_wasm_dispatch_destroy(call); - - /* resume main handler by wasm callback */ break; default: @@ -894,10 +868,9 @@ ngx_http_proxy_wasm_dispatch_resume_handler(ngx_wasm_socket_tcp_t *sock) rc = NGX_ERROR; goto error2; - } + } /* switch(call->state) */ ngx_wa_assert(rc == NGX_AGAIN || rc == NGX_OK); - goto done; error: @@ -915,15 +888,35 @@ ngx_http_proxy_wasm_dispatch_resume_handler(ngx_wasm_socket_tcp_t *sock) rc = NGX_ERROR; } - ngx_wasm_error(&rctx->env); - ngx_proxy_wasm_ctx_set_next_action(pwexec->parent, - NGX_PROXY_WASM_ACTION_CONTINUE); ngx_http_proxy_wasm_dispatch_err(call); - ngx_wa_assert(rc == NGX_ERROR); - done: + if (ngx_proxy_wasm_dispatch_calls_total(pwexec)) { + ngx_log_debug0(NGX_LOG_DEBUG_WASM, pwexec->log, 0, + "proxy_wasm more http dispatch calls pending..."); + + rc = NGX_AGAIN; + ngx_wasm_yield(&rctx->env); + ngx_proxy_wasm_ctx_set_next_action(pwexec->parent, + NGX_PROXY_WASM_ACTION_PAUSE); + + } else { + ngx_log_debug0(NGX_LOG_DEBUG_WASM, pwexec->log, 0, + "proxy_wasm last http dispatch call handled"); + + ngx_wasm_continue(&rctx->env); + ngx_proxy_wasm_ctx_set_next_action(pwexec->parent, + NGX_PROXY_WASM_ACTION_CONTINUE); + + /* resume current step if unfinished */ + if (rc != NGX_ERROR) { + rc = ngx_proxy_wasm_resume(pwexec->parent, + pwexec->parent->phase, + step); + } + } + dd("exit rc: %ld", rc); return rc; diff --git a/t/03-proxy_wasm/hfuncs/113-proxy_get_http_request_body.t b/t/03-proxy_wasm/hfuncs/113-proxy_get_http_request_body.t index f5e005808..8f209adbc 100644 --- a/t/03-proxy_wasm/hfuncs/113-proxy_get_http_request_body.t +++ b/t/03-proxy_wasm/hfuncs/113-proxy_get_http_request_body.t @@ -95,7 +95,6 @@ qr/\[info\] .*? \[wasm\] request body:/ location /t { internal; proxy_wasm hostcalls 'on=request_body'; - echo fail; } location /main { @@ -118,7 +117,6 @@ Hello from subrequest location /t { internal; proxy_wasm hostcalls 'on=request_body'; - echo fail; } location /main { @@ -142,7 +140,6 @@ Hello from main request body location /t { internal; proxy_wasm hostcalls 'on=request_body'; - echo fail; } location /main { diff --git a/t/03-proxy_wasm/hfuncs/130-proxy_dispatch_http.t b/t/03-proxy_wasm/hfuncs/130-proxy_dispatch_http.t index 9de672aff..6fa8dd1bc 100644 --- a/t/03-proxy_wasm/hfuncs/130-proxy_dispatch_http.t +++ b/t/03-proxy_wasm/hfuncs/130-proxy_dispatch_http.t @@ -152,8 +152,8 @@ qr/(\[error\]|Uncaught RuntimeError|\s+).*?dispatch failed: no :path/ host=127.0.0.10:81'; echo ok; } ---- error_code: 500 ---- response_body_like: 500 Internal Server Error +--- response_body +ok --- error_log eval qr/(\[error\]|Uncaught RuntimeError|\s+).*?dispatch failed: tcp socket - Connection refused/ --- no_error_log @@ -206,10 +206,11 @@ qq{ location /t { proxy_wasm hostcalls 'test=/t/dispatch_http_call \ host=unix:/tmp/inexistent_file.sock'; + return 201; } } ---- error_code: 500 ---- response_body_like: 500 Internal Server Error +--- error_code: 201 +--- response_body --- error_log eval [ qr/\[crit\] .*? connect\(\) to unix:\/tmp\/inexistent_file\.sock failed .*? No such file or directory/, @@ -225,10 +226,11 @@ qq{ location /t { proxy_wasm hostcalls 'test=/t/dispatch_http_call \ host=unix:/tmp'; + return 201; } } ---- error_code: 500 ---- response_body_like: 500 Internal Server Error +--- error_code: 201 +--- response_body --- error_log eval [ qr/\[error\] .*? connect\(\) to unix:\/tmp failed .*? Connection refused/, @@ -489,8 +491,8 @@ qq{ echo ok; } } ---- error_code: 500 ---- response_body_like: 500 Internal Server Error +--- response_body +ok --- error_log eval qr/(\[error\]|Uncaught RuntimeError|\s+).*?dispatch failed: tcp socket - resolver error: Host not found/ --- no_error_log @@ -896,7 +898,6 @@ Hello world path=/dispatched'; echo ok; } ---- error_code: 500 --- ignore_response_body --- error_log tcp socket trying to receive data (max: 1) @@ -925,7 +926,6 @@ tcp socket - upstream response headers too large, increase wasm_socket_large_buf path=/dispatched'; echo ok; } ---- error_code: 500 --- ignore_response_body --- error_log tcp socket trying to receive data (max: 24) @@ -954,10 +954,10 @@ sub { proxy_wasm hostcalls 'test=/t/dispatch_http_call \ host=127.0.0.1:12345'; - echo fail; + echo ok; } ---- error_code: 500 ---- response_body_like: 500 Internal Server Error +--- response_body +ok --- error_log eval [ qr/tcp socket - not enough large buffers available, increase wasm_socket_large_buffers number/, @@ -1009,10 +1009,10 @@ sub { location /t { proxy_wasm hostcalls 'test=/t/dispatch_http_call \ host=127.0.0.1:12345'; - echo fail; + echo ok; } ---- error_code: 500 ---- response_body_like: 500 Internal Server Error +--- response_body +ok --- error_log eval qr/(\[error\]|Uncaught RuntimeError|\s+).*?dispatch failed: tcp socket - parser error/ --- no_error_log @@ -1062,10 +1062,10 @@ tcp socket trying to receive data (max: 1017) host=127.0.0.1:$TEST_NGINX_SERVER_PORT \ path=/dispatched \ on_http_call_response=trap'; - echo fail; + echo ok; } ---- error_code: 500 ---- response_body_like: 500 Internal Server Error +--- response_body +ok --- error_log eval [ qr/\[crit\] .*? panicked at/, @@ -1089,10 +1089,10 @@ sub { proxy_wasm hostcalls 'test=/t/dispatch_http_call \ host=127.0.0.1:12345 \ on_http_call_response=echo_response_body'; - echo failed; + echo ok; } ---- error_code: 500 ---- response_body_like: 500 Internal Server Error +--- response_body +ok --- error_log eval qr/(\[error\]|Uncaught RuntimeError|\s+).*?dispatch failed: tcp socket - parser error/ --- no_error_log diff --git a/t/03-proxy_wasm/hfuncs/131-proxy_dispatch_http_timeouts.t b/t/03-proxy_wasm/hfuncs/131-proxy_dispatch_http_timeouts.t index f61d07eed..a9507d20f 100644 --- a/t/03-proxy_wasm/hfuncs/131-proxy_dispatch_http_timeouts.t +++ b/t/03-proxy_wasm/hfuncs/131-proxy_dispatch_http_timeouts.t @@ -33,11 +33,11 @@ qq{ proxy_wasm hostcalls 'test=/t/dispatch_http_call \ host=google.com'; - echo fail; + echo ok; } } ---- error_code: 500 ---- response_body_like: 500 Internal Server Error +--- response_body +ok --- error_log eval qr/(\[error\]|Uncaught RuntimeError|\s+).*?dispatch failed: tcp socket - timed out connecting to \".*?\"/ --- no_error_log @@ -59,11 +59,11 @@ qq{ proxy_wasm hostcalls 'test=/t/dispatch_http_call \ host=httpbin.org \ path=/status/200'; - echo fail; + echo ok; } } ---- error_code: 500 ---- response_body_like: 500 Internal Server Error +--- response_body +ok --- error_log eval qr/(\[error\]|Uncaught RuntimeError|\s+).*?dispatch failed: tcp socket - resolver error: Operation timed out/ --- no_error_log @@ -81,14 +81,14 @@ qr/(\[error\]|Uncaught RuntimeError|\s+).*?dispatch failed: tcp socket - resolve proxy_wasm hostcalls 'test=/t/dispatch_http_call \ host=127.0.0.1:$TEST_NGINX_SERVER_PORT \ path=/dispatched'; - echo fail; + echo ok; } location /dispatched { echo -n timeout_trigger; } ---- error_code: 500 ---- response_body_like: 500 Internal Server Error +--- response_body +ok --- error_log eval qr/(\[error\]|Uncaught RuntimeError|\s+).*?dispatch failed: tcp socket - timed out reading from \"127\.0\.0\.1:\d+\"/ --- no_error_log @@ -108,14 +108,14 @@ qr/(\[error\]|Uncaught RuntimeError|\s+).*?dispatch failed: tcp socket - timed o method=POST \ path=/post \ body=timeout_trigger'; - echo fail; + echo ok; } location /post { echo -n $request_body; } ---- error_code: 500 ---- response_body_like: 500 Internal Server Error +--- response_body +ok --- error_log eval qr/(\[error\]|Uncaught RuntimeError|\s+).*?dispatch failed: tcp socket - timed out writing to \".*?\"/ --- no_error_log diff --git a/t/03-proxy_wasm/hfuncs/132-proxy_dispatch_http_ssl.t b/t/03-proxy_wasm/hfuncs/132-proxy_dispatch_http_ssl.t index 2817ceaeb..9fb382c7e 100644 --- a/t/03-proxy_wasm/hfuncs/132-proxy_dispatch_http_ssl.t +++ b/t/03-proxy_wasm/hfuncs/132-proxy_dispatch_http_ssl.t @@ -207,11 +207,11 @@ qq{ proxy_wasm hostcalls 'test=/t/dispatch_http_call \ host=expired.badssl.com \ https=yes'; - echo fail; + echo ok; } } ---- error_code: 500 ---- response_body_like: 500 Internal Server Error +--- response_body +ok --- error_log eval qr/(\[error\]|Uncaught RuntimeError|\s+).*?dispatch failed: tcp socket - tls certificate verify error: \(10:certificate has expired\)/ --- no_error_log @@ -285,14 +285,14 @@ qq{ proxy_wasm hostcalls 'test=/t/dispatch_http_call \ host=localhost:$TEST_NGINX_SERVER_PORT2 \ https=yes'; - echo fail; + echo ok; } location /headers { echo $echo_client_request_headers; } ---- error_code: 500 ---- response_body_like: 500 Internal Server Error +--- response_body +ok --- error_log eval qr/(\[error\]|Uncaught RuntimeError|\s+).*?dispatch failed: tcp socket - tls certificate CN does not match \"localhost\" sni/ --- no_error_log @@ -319,11 +319,11 @@ qq{ proxy_wasm hostcalls 'test=/t/dispatch_http_call \ host=untrusted-root.badssl.com \ https=yes'; - echo fail; + echo ok; } } ---- error_code: 500 ---- response_body_like: 500 Internal Server Error +--- response_body +ok --- error_log eval qr/tls certificate verify error: \(19:self.signed certificate in certificate chain\)/ --- no_error_log @@ -342,14 +342,14 @@ qr/tls certificate verify error: \(19:self.signed certificate in certificate cha host=localhost:$TEST_NGINX_SERVER_PORT \ https=yes \ path=/dispatched'; - echo fail; + echo ok; } location /dispatched { echo -n fail; } ---- error_code: 500 ---- response_body_like: 500 Internal Server Error +--- response_body +ok --- error_log eval [ qr/\[crit\] .*? SSL_do_handshake\(\) failed/, @@ -405,10 +405,9 @@ qq{ proxy_wasm hostcalls 'test=/t/dispatch_http_call \ host=httpbin.org \ https=yes'; - echo fail; + echo ok; } } ---- error_code: 500 --- error_log eval qr/(\[error\]|Uncaught RuntimeError|\s+).*?dispatch failed: tcp socket - tls certificate verify error: \((18|20):(self-signed certificate|unable to get local issuer certificate)\)/ --- no_error_log @@ -437,11 +436,11 @@ qq{ host=httpbin.org \ https=yes \ path=/headers'; - echo fail; + echo ok; } } ---- error_code: 500 ---- response_body_like: 500 Internal Server Error +--- response_body +ok --- error_log eval qr/(\[error\]|Uncaught RuntimeError|\s+).*?dispatch failed: tcp socket - tls certificate verify error: \((18|20):(self-signed certificate|unable to get local issuer certificate)\)/ --- no_error_log @@ -510,14 +509,14 @@ qq{ https=yes \ path=/dispatch \ on_http_call_response=echo_response_body'; - echo fail; + echo ok; } location /dispatch { echo ok; } ---- error_code: 500 ---- response_body_like: 500 Internal Server Error +--- response_body +ok --- error_log eval qr/could not derive tls sni from host \("127\.0\.0\.1:\d+"\)/ --- no_error_log @@ -540,14 +539,14 @@ SNI cannot be an IP address. https=yes \ path=/dispatch \ on_http_call_response=echo_response_body'; - echo fail; + echo ok; } location /dispatch { echo ok; } ---- error_code: 500 ---- response_body_like: 500 Internal Server Error +--- response_body +ok --- error_log eval qr/could not derive tls sni from host \("\[0:0:0:0:0:0:0:1\]:\d+"\)/ --- no_error_log diff --git a/t/03-proxy_wasm/hfuncs/133-proxy_dispatch_http_edge_cases.t b/t/03-proxy_wasm/hfuncs/133-proxy_dispatch_http_edge_cases.t index c8ac4634d..a9c41c2da 100644 --- a/t/03-proxy_wasm/hfuncs/133-proxy_dispatch_http_edge_cases.t +++ b/t/03-proxy_wasm/hfuncs/133-proxy_dispatch_http_edge_cases.t @@ -373,3 +373,27 @@ qr/\A.*? on_request_headers.* [error] [crit] [emerg] + + + +=== TEST 11: proxy_wasm - dispatch_http_call() 2 failing parallel calls +--- valgrind +--- wasm_modules: hostcalls +--- config + location /t { + proxy_wasm hostcalls 'on=request_headers \ + test=/t/dispatch_http_call \ + host=127.0.0.1:1 \ + ncalls=2'; + return 201; + } +--- error_code: 201 +--- response_body +--- grep_error_log eval: qr/\[error\] .*? dispatch failed.*/ +--- grep_error_log_out eval +qr/\A\[error] .*? dispatch failed: tcp socket - Connection refused +\[error] .*? dispatch failed: tcp socket - Connection refused\Z/ +--- no_error_log +[crit] +[emerg] +[alert] diff --git a/t/04-openresty/ffi/200-proxy_wasm_and_lua_sanity.t b/t/04-openresty/ffi/200-proxy_wasm_and_lua_sanity.t index 1f53c2b86..c2f80571e 100644 --- a/t/04-openresty/ffi/200-proxy_wasm_and_lua_sanity.t +++ b/t/04-openresty/ffi/200-proxy_wasm_and_lua_sanity.t @@ -358,11 +358,11 @@ qr/\A\*\d+ .*? filter 1\/1 resuming "on_request_headers" step in "rewrite" phase } content_by_lua_block { - ngx.say("fail") + ngx.say("ok") } } ---- error_code: 500 ---- response_body_like: 500 Internal Server Error +--- response_body +ok --- error_log eval [ qr/on_http_call_response \(id: \d+, status: 200, headers: 5, body_bytes: \d+, trailers: 0, op: trap\)/, diff --git a/t/04-openresty/lua-bridge/002-proxy_wasm_lua_resolver_sanity.t b/t/04-openresty/lua-bridge/002-proxy_wasm_lua_resolver_sanity.t index 02ddca5c7..b94b9c40d 100644 --- a/t/04-openresty/lua-bridge/002-proxy_wasm_lua_resolver_sanity.t +++ b/t/04-openresty/lua-bridge/002-proxy_wasm_lua_resolver_sanity.t @@ -466,17 +466,18 @@ hello world proxy_wasm hostcalls 'on=request_headers \ test=/t/dispatch_http_call \ host=foo'; - echo failed; + echo ok; } ---- error_code: 500 ---- response_body_like: 500 Internal Server Error +--- response_body +ok --- grep_error_log eval: qr/\[error\].*/ --- grep_error_log_out eval qr/\[error\] .*? lua user thread aborted: .*? wasm lua failed resolving "foo": dns client error: 101 empty record received.*? -\[error\] .*? dispatch failed: tcp socket - lua resolver failed.*?/ +\[error\] .*? dispatch failed: tcp socket - lua resolver failed/ +--- error_log eval +qr/\[info\] .*? filter chain failed resuming: previous error \(dispatch failure\).*?/ --- no_error_log [crit] -[emerg] @@ -509,14 +510,16 @@ Failure before the Lua thread gets a chance to yield (immediate resolver failure host=httpbin.org \ path=/ \ on_http_call_response=echo_response_body'; - echo failed; + echo ok; } ---- error_code: 500 ---- response_body_like: 500 Internal Server Error +--- response_body +ok --- grep_error_log eval: qr/\[error\].*/ --- grep_error_log_out eval qr/\[error\] .*? lua user thread aborted: .*? wasm lua failed resolving "httpbin\.org": some made-up error.*? -\[error\] .*? dispatch failed\Z/ +\[error\] .*? dispatch failed/ +--- error_log eval +qr/\[info\] .*? filter chain failed resuming: previous error \(dispatch failure\).*?/ --- error_log wasm tcp socket resolver failed before query --- no_error_log diff --git a/t/04-openresty/lua-bridge/003-proxy_wasm_lua_resolver_timeouts.t b/t/04-openresty/lua-bridge/003-proxy_wasm_lua_resolver_timeouts.t index 0c76c8939..733cf8a37 100644 --- a/t/04-openresty/lua-bridge/003-proxy_wasm_lua_resolver_timeouts.t +++ b/t/04-openresty/lua-bridge/003-proxy_wasm_lua_resolver_timeouts.t @@ -83,10 +83,10 @@ qq{ test=/t/dispatch_http_call \ host=timeout_trigger'; echo_sleep 0.3; - echo failed; + echo ok; } ---- error_code: 500 ---- response_body_like: 500 Internal Server Error +--- response_body +ok --- grep_error_log eval: qr/\[error\].*/ --- grep_error_log_out eval qr/\[error\] .*? lua udp socket read timed out.*? @@ -132,7 +132,7 @@ qq{ --- config location /t { proxy_wasm_lua_resolver on; - proxy_wasm hostcalls 'tick_period=5 \ + proxy_wasm hostcalls 'tick_period=300 \ on_tick=dispatch \ host=httpbin.org \ path=/headers';