==19824== 224 bytes in 1 blocks are definitely lost in loss record 13 of 33
==19824== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==19824== by 0x1E56AA: ngx_alloc (ngx_alloc.c:22)
==19824== by 0x1CF926: ngx_resolver_alloc (ngx_resolver.c:4400)
==19824== by 0x1CF926: ngx_resolver_calloc.isra.0 (ngx_resolver.c:4413)
==19824== by 0x1D1EFD: ngx_resolve_start (ngx_resolver.c:661)
==19824== by 0x392C80: ngx_wasm_socket_tcp_connect (ngx_wasm_socket_tcp.c:360)
==19824== by 0x3BC984: ngx_http_proxy_wasm_dispatch_resume_handler (ngx_http_proxy_wasm_dispatch.c:745)
==19824== by 0x3BD4C3: ngx_http_proxy_wasm_dispatch_handler (ngx_http_proxy_wasm_dispatch.c:477)
==19824== by 0x1DFBE9: ngx_event_process_posted (ngx_event_posted.c:35)
==19824== by 0x1DF0E6: ngx_process_events_and_timers (ngx_event.c:273)
==19824== by 0x1EE697: ngx_single_process_cycle (ngx_process_cycle.c:323)
==19824== by 0x1A9078: main (nginx.c:384)
This was caused by having 2 parallel dispatch calls using pwm_lua_resolver DNS resolution. When the first call responds and produces a downstream response, it causes pending calls to be cancelled.
However when a cancelled call had not yet finished the Lua-bridge DNS resolution, its associated rslv_ctx was never freed.
This adds a "cancel" feature to Lua bridge threads, which is invoked by TCP sockets when they are closed while having a pending Lua resolver thread.
An occasional memory leak of Proxy-Wasm dispatch with Lua bridge resolver, spotted by CI:
https://github.com/Kong/ngx_wasm_module/actions/runs/9884094484/job/27299927250
This was caused by having 2 parallel dispatch calls using
pwm_lua_resolver
DNS resolution. When the first call responds and produces a downstream response, it causes pending calls to be cancelled.However when a cancelled call had not yet finished the Lua-bridge DNS resolution, its associated
rslv_ctx
was never freed.This adds a "cancel" feature to Lua bridge threads, which is invoked by TCP sockets when they are closed while having a pending Lua resolver thread.