wasilibs/nottinygc

nottinygc memory leak with fastcache

LoremipsumSharp opened this issue · 2 comments

Description

I am developing a WASM plugin for Istio ingress gateway. In the WASM Plugin, the fastcache is used for caching and the total cache size is limit to 32MB for preventing the OOM, however, the memory usage still keeps increasing

How to reproduce

dependecy:

  • tinygo v0.28.1
  • nottinygc v0.4.0
  • proxy-wasm-go-sdk v0.22.0
  • istion v1.18.0

The code of plugin to describe the issuse :

proxy-wasm-memory-leak

I`ve modify the source code of fastcache to make it can be compiled with tinygo

The Test script:

func TestMemoryLeak(t *testing.T) {
// Ingress Host and port :192.168.58.3:31505
	req, err := http.NewRequest("GET", "http://192.168.58.3:31505", nil)
	if err != nil {
		panic(err)
	}
	for i := 0; i < 10000000; i++ {
		_, err := http.DefaultClient.Do(req)
		if err != nil {
			continue
		}
	}
	fmt.Println("done")
}

what I’ve inspect is that is memory is keep increasing and never release

Thanks @LoremipsumSharp - I have been able to reproduce with a simple snippet using wazero without proxy-wasm-go-sdk or Envoy. Will try to debug this but it may take some time

Hi @LoremipsumSharp - very sorry it took so long to get some time to debug this. I tried running a fastcache loop without nottinygc using the default TinyGo GC and had the same memory leak behavior. So I believe this may not be an issue with nottinygc but just with TinyGo + fastcache interaction itself. Note that TinyGo has had memory leak issues with map keys before (one is tinygo-org/tinygo#3483) and latest version may still have some.

Anyways, because wasm plugins are single threaded, fastcache is very much overkill. If you can, you may consider using just a normal Go map, there is no need for any locking or atomics.

I am going to go ahead and close this but please feel free to reopen if you think the issue is actually nottinygc-specific!