-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(*) resolve a potential memleak in Lua bridge resolver
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 ==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. Alas no test since we would need to mock an entire DNS server.
- Loading branch information
1 parent
cce2457
commit f5d681c
Showing
5 changed files
with
76 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters