Custom middleware plugin, vendored code analysis - false positive compile error

Dear Traefik Pilot,
At first I would like to thank you for your great work.
I've written some traefik middleware plugin that is checking the country of provided input request and allows blocking unwanted traffic. At first I've forked some geoblock repository and applied my custom changes. I've quickly realised that forks are not being analyzed, and I've deleted given repository and created some non-forked based repository.

And success, traefik pilot have finally found my repository, but it found some issue.
It says that:

failed to run the plugin with Yaegi: the load of the plugin takes too much time(10s), or an error, inside the plugin, occurs during the load: 1:21: import "" error: /tmp/pilot-gop2605749730/src/ import "" error: /tmp/pilot-gop2605749730/src/ cannot use type []uint8 as type int64

I've quickly checked that issue, but I think that the analyser is wrong. It says that there is some compile error in that code line:

I've provided some basic CI/CD with some go tests, as well as some basic golangci-lint.
Do you know what might be wrong in that topic?

Traefik uses Yaegi to interpret plugin's code. You can try running yaegi test in your CI to check with the plugin code with the interpreter itself.

FYI, I've tested your plugin with Yaegi, and I've got the same error:

> yaegi test
test: plugin.go:13:2: import "" error: /home/tmp/go/src/ cannot use type []uint8 as type int64

1 Like

Which version of yaegi are you using? When I'm using 0.10.0 the output is only about the test files - which is also weird.

test: plugin_test.go:10:2: import "" error: /home/kucjac/Developer/golang/src/ import "" error: /home/kucjac/Developer/golang/src/ import "" error: /home/kucjac/Developer/golang/src/ import "unsafe" error: unable to find source related to: "unsafe"

No matter what, it still looks like it is somehow an error with an interpreter, isn't it? Do you know any possible solutions that solves that issue?

I still don't get why this:

type DBReader interface {

Included in this:

type DB struct {
	f    DBReader
	meta ip2locationmeta

could be interpreted incorrectly within this function:

// read byte
func (d *DB) readuint8(pos int64) (uint8, error) {
	var retval uint8
	data := make([]byte, 1)
	_, err := d.f.ReadAt(data, pos-1) // This line fails
	if err != nil {
		return 0, err
	retval = data[0]
	return retval, nil

Anyway, I'll play with it and try to change the interface to some specific structure, maybe this would work better.

I'm using the same as Traefik itself (Yaegi@v0.10.0).

Anyway, Traefik does not allow using "unsafe" in a plugin, so you might want to look into another solution.

Hmm... All the usage of the which indirectly is using unsafe package was in the test files. Thus, it probably should not be counted in terms of plugin - as its content should not be also included into binary.
I've commented out the content of the test file, tidy the go module and vendor. Locally, yaegi passes, and I'm curious if it would also on the test.

Thanks again @tommoulard for your response.

It looks like, that both an interface that was importing another interface that was importing another interface was a problem, as well as the package (that uses unsafe package) for test purposes.
Anyway thanks again for the help. The problem is already solved.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.