Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory allocation panic in WASM plugin during normal operation #11436

Open
2 tasks done
skosch opened this issue Jan 10, 2025 · 0 comments
Open
2 tasks done

Memory allocation panic in WASM plugin during normal operation #11436

skosch opened this issue Jan 10, 2025 · 0 comments
Labels
area/plugins kind/bug/confirmed a confirmed bug (reproducible).

Comments

@skosch
Copy link

skosch commented Jan 10, 2025

Welcome!

  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've searched similar issues on the Traefik community forum and didn't find any.

What did you do?

I use Traefik v3 with this Traefik OIDC auth plugin. The plugin uses http-wasm-host-go with the forked traefik/http-wasm-guest-tinygo.

I opened an issue here weeks ago, but have not received a response. I hope it's okay to crosspost here, in case the problem lies with Traefik; otherwise please feel free to close and redirect me elsewhere.

This is unrelated to the memory leak problems discussed in #11116. I experienced those as well, but more recent versions of Traefik have been fine.

What did you see instead?

Certain requests cause the runtime to crash, causing downtime until I manually restart Traefik. I have not been able to detect what, if anything, the problematic requests have in common.

The plugin calls GetURI via GetString, which fails when trying to allocate memory for the returned string(...):

func GetString(fn func(ptr uint32, limit imports.BufLimit) (len uint32)) (result string) {
	size := fn(ReadBufPtr, ReadBufLimit)
	if size == 0 {
		return // If nothing was read, return an empty string.
	} else if size <= ReadBufLimit {
		return string(ReadBuf[:size]) // string will copy the buffer.  <-------  THIS FAILS!
	}
	...
}

Here's a stacktrace:

runtime.throw({0xab3e1, 0x2a})
	/home/runner/sdk/gotip/src/runtime/panic.go:1074 +0x3 fp=0x48c1d8 sp=0x48c1b0 pc=0x14a00003
runtime.sigpanic()
	/home/runner/sdk/gotip/src/runtime/os_wasm.go:26 +0xe fp=0x48c1f8 sp=0x48c1d8 pc=0x121a000e
runtime.mallocgcSmallNoscan(0x22, 0x0, 0x0)
	/home/runner/sdk/gotip/src/runtime/malloc.go:1267 +0x26 fp=0x48c250 sp=0x48c1f8 pc=0x10970026
runtime.mallocgc(0x22, 0x0, 0x0)
	/home/runner/sdk/gotip/src/runtime/malloc.go:1046 +0x17 fp=0x48c288 sp=0x48c250 pc=0x14660017
runtime.slicebytetostring(0x0, 0x86a000, 0x22)
	/home/runner/sdk/gotip/src/runtime/string.go:156 +0xb fp=0x48c2b8 sp=0x48c288 pc=0x1339000b
github.com/http-wasm/http-wasm-guest-tinygo/handler/internal/mem.GetString(0xb8a00)
	/home/runner/go/pkg/mod/github.com/traefik/http-wasm-guest-tinygo@v0.0.0-20240913140402-af96219ffea5/handler/internal/mem/mem.go:44 +0x8 fp=0x48c310 sp=0x48c2b8 pc=0x26c80008
github.com/http-wasm/http-wasm-guest-tinygo/handler.wasmRequest.GetURI(...)
	/home/runner/go/pkg/mod/github.com/traefik/http-wasm-guest-tinygo@v0.0.0-20240913140402-af96219ffea5/handler/request.go:31
github.com/http-wasm/http-wasm-guest-tinygo/handler.(*wasmRequest).GetURI(0x482a60)
	<autogenerated>:1 +0x5 fp=0x48c330 sp=0x48c310 pc=0x26e90005
main.(*TraefikOIDCWasm).handleRequest(0x8607c0, {0x114ef8, 0x482a60}, {0x1142d0, 0x482a60})
	/home/runner/work/traefik-oidc-wasm/traefik-oidc-wasm/main.go:107 +0xd fp=0x48c388 sp=0x48c330 pc=0x274e000d
...

I suspect that malloc.go:1267 probably refers to this line in a version from October:

...
c := getMCache(mp)
var sizeclass uint8
if size <= smallSizeMax-8 {
	sizeclass = size_to_class8[divRoundUp(size, smallSizeDiv)]
} else {
	sizeclass = size_to_class128[divRoundUp(size-smallSizeMax, largeSizeDiv)]
}
size = uintptr(class_to_size[sizeclass])
spc := makeSpanClass(sizeclass, true)
span := c.alloc[spc]  // <-- HERE
...

which would suggest that it can't get an MCache for some reason – but here I'm unfortunately out of my depth, having no experience with Go or WASM.

I would be grateful for any ideas.

What version of Traefik are you using?

3.2.1

What is your environment & configuration?

http:
    oidc-auth:
      plugin:
        traefik-oidc-wasm:
           claimMap:
             upn: uid
           enable: true
           endpoint:
             callback: /blablabla
           provider:
             clientID: "blablabla"
             clientSecret: "blablabla"
             issuerUrl: "https://...."
             scopes:
               - openid
               - profile
               - email
          "--log.level=DEBUG",
          "--accesslog=false",
          "--accesslog.filepath=/local/accesslog",
          "--accesslog.format=json",
          "--accesslog.fields.defaultMode=keep",
          "--accesslog.fields.names.ClientUsername=drop",
          "--accesslog.fields.headers.defaultMode=keep",
          "--accesslog.fields.headers.names.User-Agent=redact",
          "--accesslog.fields.headers.names.Authorization=drop",
          "--accesslog.fields.headers.names.Content-Type=keep",
          "--experimental.plugins.traefik-oidc-wasm.modulename=github.com/xzzpig/traefik-oidc-wasm",
          "--experimental.plugins.traefik-oidc-wasm.version=v0.0.6",

If applicable, please paste the log output in DEBUG level

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/plugins kind/bug/confirmed a confirmed bug (reproducible).
Projects
None yet
Development

No branches or pull requests

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy