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

ig panics when it fails to create container-collection #2812

Open
alban opened this issue May 7, 2024 · 1 comment
Open

ig panics when it fails to create container-collection #2812

alban opened this issue May 7, 2024 · 1 comment

Comments

@alban
Copy link
Member

alban commented May 7, 2024

Description

ig panics when it fails to create container-collection

Impact

time="2024-05-07T10:43:32Z" level=info msg="Experimental features enabled"
time="2024-05-07T10:43:36Z" level=warning msg="Failed to create container-collection"
time="2024-05-07T10:43:37Z" level=warning msg="Failed to create container-collection"
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1fd12bd]

goroutine 1 [running]:
github.com/inspektor-gadget/inspektor-gadget/pkg/operators/localmanager.(*localManagerTraceWrapper).PreStart(0xc003914180, {0x2f5d840, 0xc0036de000})
        /go/src/github.com/inspektor-gadget/inspektor-gadget/pkg/operators/localmanager/localmanager.go:532 +0xbd
github.com/inspektor-gadget/inspektor-gadget/pkg/gadget-context.(*GadgetContext).run(0xc0036de000, {0xc0036dc0f0, 0x4, 0xc0015c7a00?})
        /go/src/github.com/inspektor-gadget/inspektor-gadget/pkg/gadget-context/run.go:101 +0x1a7
github.com/inspektor-gadget/inspektor-gadget/pkg/gadget-context.(*GadgetContext).Run(0xc0036de000, 0xc0036d20f0?)
        /go/src/github.com/inspektor-gadget/inspektor-gadget/pkg/gadget-context/run.go:158 +0x9e
github.com/inspektor-gadget/inspektor-gadget/pkg/runtime/local.(*Runtime).RunOCIGadget(0x22257e0?, {0x2f868a0?, 0xc0036de000?}, 0xd?, 0xc0015c7b18?)
        /go/src/github.com/inspektor-gadget/inspektor-gadget/pkg/runtime/local/oci.go:35 +0x27
github.com/inspektor-gadget/inspektor-gadget/cmd/common.NewRunCommand.func2(0xc00067c000, {0xc00061b8c0?, 0x3?, 0x3?})
        /go/src/github.com/inspektor-gadget/inspektor-gadget/cmd/common/oci.go:174 +0x697
github.com/spf13/cobra.(*Command).execute(0xc00067c000, {0xc00061b8c0, 0x3, 0x3})
        /go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:983 +0xabc
github.com/spf13/cobra.(*Command).ExecuteC(0xc000005b00)
        /go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
        /go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1039
main.main()
        /go/src/github.com/inspektor-gadget/inspektor-gadget/cmd/ig/main.go:89 +0x374

Environment and steps to reproduce

I don't have the steps or the environment, I'll try to find more details.

Start ig in a Kubernetes pod:

ig run albantest.azurecr.io/trace_udns:t1 -o json

Expected behavior

ig should not panic.

Additional information

https://github.com/inspektor-gadget/inspektor-gadget/blob/v0.27.0/pkg/operators/localmanager/localmanager.go#L532

func (l *localManagerTraceWrapper) PreStart(gadgetCtx operators.GadgetContext) error {
	// hack - this makes it possible to use the Attacher interface
	var ok bool
	l.gadgetInstance, ok = gadgetCtx.GetVar("ebpfInstance")
	if !ok {
		return fmt.Errorf("getting ebpfInstance")
	}

	compat.Subscribe(
		l.eventWrappers,
		l.manager.igManager.ContainerCollection.EnrichEventByMntNs,
		l.manager.igManager.ContainerCollection.EnrichEventByNetNs,
		0,
	)

Presumably, l.manager.igManager.ContainerCollection is nil. The function PreStart should check this.

cc @flyth

@alban
Copy link
Member Author

alban commented May 8, 2024

I tried to synthetise the error with:

--- a/pkg/container-collection/options.go
+++ b/pkg/container-collection/options.go
@@ -672,7 +672,7 @@ func WithContainerFanotifyEbpf() ContainerCollectionOption {
                        }
                        return true
                })
-               return nil
+               return fmt.Errorf("lets fail on WithContainerFanotifyEbpf")
        }
 }
 

And then run:

go run -exec 'sudo -E' ./cmd/ig/... trace exec --host -c mycontainer

So I get the warnings:

WARN[0000] Failed to create container-collection        
WARN[0000] container-collection isn't available: container enrichment and filtering won't work 

But localManagerTraceWrapper.PreStart is not called in my tests. PreStart has the same interface as other PreStart functions. In fact, when I add a panic() in GadgetContext.run, it is not called.

I am not sure of the differences between LocalManager, localManagerTrace and localManagerTraceWrapper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 New
Development

No branches or pull requests

1 participant