Skip to content

Panic nil pointer when using popular ttlcache library #1696

@sandoichi

Description

@sandoichi

The following program sample.go triggers an unexpected result

package main

import (
	_ "github.com/jellydator/ttlcache/v3"
	"github.com/traefik/yaegi/interp"
	"github.com/traefik/yaegi/stdlib"
)

func main() {
	i := interp.New(interp.Options{
               // go mod vendor into ./src
		GoPath: ".",
	})

	i.Use(stdlib.Symbols)

	_, err := i.Eval(`import "github.com/jellydator/ttlcache/v3"`)
	if err != nil {
		panic(err)
	}

	_, err = i.Eval(`var cache *ttlcache.Cache[string, string]`)
	if err != nil {
		panic(err)
	}

}

Expected result

should run without issue

Got

go run .
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x128 pc=0x6d49df]

goroutine 1 [running]:
github.com/traefik/yaegi/interp.nodeType2(0xc0000ff448, 0xc000184c60, 0xc000537180, {0xc0004b8bc0, 0x3, 0x4})
	/home/chris/go/pkg/mod/github.com/traefik/[email protected]/interp/type.go:1083 +0x397f
github.com/traefik/yaegi/interp.nodeType2(0xc0000ff448, 0xc000184c60, 0xc000536c80, {0xc0004b8bc0, 0x2, 0x4})
	/home/chris/go/pkg/mod/github.com/traefik/[email protected]/interp/type.go:1079 +0x3957
github.com/traefik/yaegi/interp.genType(0xc0000ff448, 0xc000184c60, {0xc00003a5a0, 0x1d}, 0xc000575540, {0xc0004a6880, 0x2, 0x2}, {0xc0004a6870, 0x2, ...})
	/home/chris/go/pkg/mod/github.com/traefik/[email protected]/interp/type.go:1136 +0xcb
github.com/traefik/yaegi/interp.nodeType2(0xc0000ff448, 0xc000184c60, 0xc000533e00, {0xc0004a6870, 0x1, 0x2})
	/home/chris/go/pkg/mod/github.com/traefik/[email protected]/interp/type.go:898 +0x533f
github.com/traefik/yaegi/interp.nodeType2(0xc0000ff448, 0xc000184c60, 0xc000533cc0, {0xc0006a5320, 0x0, 0x1})
	/home/chris/go/pkg/mod/github.com/traefik/[email protected]/interp/type.go:425 +0x2dda
github.com/traefik/yaegi/interp.nodeType(...)
	/home/chris/go/pkg/mod/github.com/traefik/[email protected]/interp/type.go:400
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc000533a40)
	/home/chris/go/pkg/mod/github.com/traefik/[email protected]/interp/gta.go:118 +0x1b51
github.com/traefik/yaegi/interp.(*node).Walk(0xc000533a40, 0xc000597c18, 0x0)
	/home/chris/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:282 +0x2e
github.com/traefik/yaegi/interp.(*node).Walk(0xc000533900, 0xc000597c18, 0x0)
	/home/chris/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:286 +0x6b
github.com/traefik/yaegi/interp.(*node).Walk(0xc000533680, 0xc000597c18, 0x0)
	/home/chris/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:286 +0x6b
github.com/traefik/yaegi/interp.(*Interpreter).gta(0xc0000ff448, 0xc000533680, {0xc00048ff08, 0x4}, {0xc00048ff08, 0x4}, {0xc00048ff08, 0x4})
	/home/chris/go/pkg/mod/github.com/trae
fik/[email protected]/interp/gta.go:20 +0x22b
github.com/traefik/yaegi/interp.(*Interpreter).gtaRetry(0xc0000ff448, {0xc000597e00?, 0xc000193860?, 0xc000597d38?}, {0xc00048ff08, 0x4}, {0xc00048ff08, 0x4})
	/home/chris/go/pkg/mod/github.com/traefik/[email protected]/interp/gta.go:395 +0x152
github.com/traefik/yaegi/interp.(*Interpreter).CompileAST(0xc0000ff448, {0x11069e8?, 0xc000193860?})
	/home/chris/go/pkg/mod/github.com/traefik/[email protected]/interp/program.go:92 +0x113
github.com/traefik/yaegi/interp.(*Interpreter).compileSrc(0xc0000ff448, {0xf754e5?, 0x0?}, {0x0?, 0xc00034dd78?}, 0x20?)
	/home/chris/go/pkg/mod/github.com/traefik/[email protected]/interp/program.go:64 +0xaa
github.com/traefik/yaegi/interp.(*Interpreter).eval(0xc0000ff448, {0xf754e5?, 0x0?}, {0x0?, 0x0?}, 0x0?)
	/home/chris/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:554 +0x25
github.com/traefik/yaegi/interp.(*Interpreter).Eval(...)
	/home/chris/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:496
main.main()
	/home/chris/os_testing/yaegi-test/main.go:21 +0x9d
exit status 2

Yaegi Version

0.16.1

Additional Notes

I have been working on a traefik middleware plugin and recently added the popular github.com/jellydator/ttlcache/v3 package to it. When doing so, my traefik pod would throw yaegi nil reference exceptions when starting up and loading the plugin.

I tried to locally interpret the plugin code with the latest yaegi cli and saw the same result. I then created the sample go program above, and also had the same result there (note that in the sample app, ./src exists with vendored package directory tree inside, to be used as the GOPATH).

The error output doesn't really tell me what went wrong or if there is anything I can do to fix it. I assume that this is some type of bug and should not be occurring.

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