Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Memory leak when using GetHttpRequestHeaders  #349

Description

@ggmm-0

Describe the bug / error

It seems that memory allocated for the headers (when using proxywasm.GetHttpRequestHeaders()) is never freed up. The memory keeps growing linearly.

When Envoy process consumes e.g. 800 MB, Envoy /memory endpoint reports only ~45-50 MB (also its heap dump shows the same) - that is why I suspect Wasm allocated heap (which I believe isn't reported by Envoy). Removing proxywasm.GetHttpRequestHeaders() from the snippet below gets rid of the problem (stable 45-50 MB memory consumption by the whole process).

What is your Envoy/Istio version?

Envoy built from source (commit be8e01e from 14 Oct, 2022: envoyproxy/envoy@be8e01e).

What is the SDK version?

github.com/tetratelabs/proxy-wasm-go-sdk v0.20.0

What is your TinyGo version?

TinyGo from official docker image: tinygo/tinygo:0.26.0.

URL or snippet of your code including Envoy configuration

I'm including the full example as it is a tiny sample application with a few custom lines. Most of it are proxywasm overrides and the actual code is in OnHttpRequestHeaders:

package main

import (
	"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
	"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types"
)

func main() {
	proxywasm.SetVMContext(&vmContext{})
}

type (
	vmContext     struct{}
	pluginContext struct {
		// Embed the default plugin context here,
		// so that we don't need to reimplement all the methods.
		types.DefaultPluginContext``
	}

	httpContext struct {
		// Embed the default http context here,
		// so that we don't need to reimplement all the methods.
		types.DefaultHttpContext
	}
)

// Override types.VMContext.
func (*vmContext) OnVMStart(vmConfigurationSize int) types.OnVMStartStatus {
	return types.OnVMStartStatusOK
}

// Override types.DefaultVMContext.
func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext {
	return &pluginContext{}
}

// Override types.DefaultPluginContext.
func (*pluginContext) NewHttpContext(contextID uint32) types.HttpContext {
	return &httpContext{}
}

func (ctx *httpContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action {
	headers, err := proxywasm.GetHttpRequestHeaders()
	if err != nil || len(headers) == 0 {
		proxywasm.LogCriticalf("Failed to get request headers: %v", err)
	}
	return types.ActionContinue
}

Relevant Envoy config:

http_filters:
  - name: envoy.filters.http.wasm
     typed_config:
       "@type": type.googleapis.com/udpa.type.v1.TypedStruct
       type_url: type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm
       value:
         config:
           vm_config:
             runtime: "envoy.wasm.runtime.v8"
             code:
               local:
                 filename: "/var/headers.wasm" 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions