Skip to content

Conversation

@ttys3
Copy link
Contributor

@ttys3 ttys3 commented Oct 1, 2024

fixup guest module instance creation without guest module free caused memory leak

related issue: traefik/traefik#11119

related PR: traefik#2

cc @juliens


since this implementation make usage of sync.Pool

we must call Close() method of the module when the sync.Pool object got GC ed.

without call Close() to releases resources allocated for this Module, the memory will leak


related PR

see also traefik/traefik#11151 which fixup the wasm plugin memory leak when dynamic config loading ( which cause all related route middleware recreation), we have to call nethttp.middleware.Close() (which will call handler.middleware.Close() -> wazero.Runtime.Close() ) to free the memory

@ttys3 ttys3 changed the title fix: fix wasm plugin memory leak issue fix: fix wasm guest module memory leak issue Oct 1, 2024
@ttys3 ttys3 force-pushed the memory_leak_fixup branch from 0ef7f5d to 04fd875 Compare October 1, 2024 16:12
@ttys3 ttys3 changed the title fix: fix wasm guest module memory leak issue fix: fix wasm middleware plugin memory leak issue Oct 1, 2024
@ttys3 ttys3 marked this pull request as draft October 1, 2024 16:34
@ttys3 ttys3 marked this pull request as ready for review October 2, 2024 02:26
@ttys3
Copy link
Contributor Author

ttys3 commented Oct 2, 2024

imports style fixed, please approve CI actions

@jcchavezs
Copy link
Collaborator

Thanks for this @ttys3, any chance you can port the benchmarks into this PR?

@ttys3
Copy link
Contributor Author

ttys3 commented Oct 2, 2024

Thanks for this @ttys3, any chance you can port the benchmarks into this PR?

I have all things to reproduce and verify the leak issue and the PR fixed the issue in the repo: https://github.com/ttys3/traefik-wasm-plugin-memory-leak-demo/

but I do not know how to port them to this.

any advice ? @jcchavezs

@jcchavezs
Copy link
Collaborator

I think the main issue comes from traefik/traefik#11119 (comment)

@ttys3 ttys3 changed the title fix: fix wasm middleware plugin memory leak issue fix: fix wasm middleware guest module instance memory leak issue Oct 2, 2024
@ttys3
Copy link
Contributor Author

ttys3 commented Oct 2, 2024

I think the main issue comes from traefik/traefik#11119 (comment)

I think it's just the opposite; that leak is secondary. The main leak is addressed in this PR.

They are two different types of leaks. Although they have similar symptoms, they are not the same issue.

@ttys3 ttys3 force-pushed the memory_leak_fixup branch from 4faa707 to b074ca8 Compare October 3, 2024 03:21
@jcchavezs jcchavezs merged commit 5ad5dad into http-wasm:main Oct 3, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants