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

Error: runtime error: invalid memory address or nil pointer dereference (3.3.8) #9269

Closed
Siebjee opened this issue Aug 1, 2022 · 5 comments · Fixed by #9787
Closed

Error: runtime error: invalid memory address or nil pointer dereference (3.3.8) #9269

Siebjee opened this issue Aug 1, 2022 · 5 comments · Fixed by #9787
Labels
area/controller Controller issues, panics P1 High priority. All bugs with >=5 thumbs up that aren’t P0, plus: Any other bugs deemed high priority solution/suggested A solution to the bug has been suggested. Someone needs to implement it. type/bug

Comments

@Siebjee
Copy link
Contributor

Siebjee commented Aug 1, 2022

Summary

When a valueFrom is used in a workflow parameter (arguments.parameters) it produces a:

Error: runtime error: invalid memory address or nil pointer dereference

What version are you running?

3.3.8

Diagnostics

Paste the smallest workflow that reproduces the bug. We must be able to run the workflow.

apiVersion: v1
kind: Secret
type: Opaque
metadata:
  name: my-secret
data:
  test: changeme

---
# The coinflip example combines the use of a script result,
# along with conditionals, to take a dynamic path in the
# workflow. In this example, depending on the result of the
# first step, 'flip-coin', the template will either run the
# 'heads' step or the 'tails' step.
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  name: test-workflow-parameters-1
  annotations:
    workflows.argoproj.io/description: |
      This is an example of coin flip defined as a sequence of conditional steps.
      You can also run it in Python: https://couler-proj.github.io/couler/examples/#coin-flip
spec:
  entrypoint: coinflip
  arguments:
    parameters:
    - name: foobar
      valueFrom:
        secretKeyRef:
          name: my-secret
          key: test

  templates:
  - name: coinflip
    steps:
    - - name: flip-coin
        template: flip-coin
    - - name: heads
        template: heads
        when: "{{steps.flip-coin.outputs.result}} == heads"
      - name: tails
        template: tails
        when: "{{steps.flip-coin.outputs.result}} == tails"

  - name: flip-coin
    script:
      image: python:alpine3.6
      command: [python]
      source: |
        import random
        result = "heads" if random.randint(0,1) == 0 else "tails"
        print(result)
  - name: heads
    container:
      image: alpine:3.6
      command: [sh, -c]
      args: ["echo \"it was heads\""]

  - name: tails
    container:
      image: alpine:3.6
      command: [sh, -c]
      args: ["echo \"it was tails\""]
# Logs from the workflow controller:
kubectl logs -n argo deploy/workflow-controller | grep ${workflow} 

time="2022-08-01T12:12:03.772Z" level=info msg="Processing workflow" namespace=siebren workflow=test-workflow-parameters-1
time="2022-08-01T12:12:03.774Z" level=error msg="Recovered from panic" namespace=siebren r="runtime error: invalid memory address or nil pointer dereference" stack="goroutine 302 [running]:\nruntime/debug.Stack()\n\t/usr/local/go/src/runtime/debug/stack.go:24 +0x65\ngithub.com/argoproj/argo-workflows/v3/workflow/controller.(*wfOperationCtx).operate.func2()\n\t/go/src/github.com/argoproj/argo-workflows/workflow/controller/operator.go:194 +0xd4\npanic({0x1ce07c0, 0x33713e0})\n\t/usr/local/go/src/runtime/panic.go:1047 +0x266\ngithub.com/argoproj/argo-workflows/v3/workflow/controller.(*wfOperationCtx).setGlobalParameters(0xc001362d80, {{0xc000371ec0, 0x1, 0x1}, {0x0, 0x0, 0x0}})\n\t/go/src/github.com/argoproj/argo-workflows/workflow/controller/operator.go:571 +0xf22\ngithub.com/argoproj/argo-workflows/v3/workflow/controller.(*wfOperationCtx).setExecWorkflow(0xc001362d80, {0x22b0668, 0xc000058018})\n\t/go/src/github.com/argoproj/argo-workflows/workflow/controller/operator.go:3527 +0x726\ngithub.com/argoproj/argo-workflows/v3/workflow/controller.(*wfOperationCtx).operate(0xc001362d80, {0x22b0668, 0xc000058018})\n\t/go/src/github.com/argoproj/argo-workflows/workflow/controller/operator.go:208 +0x209\ngithub.com/argoproj/argo-workflows/v3/workflow/controller.(*WorkflowController).processNextItem(0xc00008dc00, {0x22b0668, 0xc000058018})\n\t/go/src/github.com/argoproj/argo-workflows/workflow/controller/controller.go:756 +0x8ee\ngithub.com/argoproj/argo-workflows/v3/workflow/controller.(*WorkflowController).runWorker(0x0)\n\t/go/src/github.com/argoproj/argo-workflows/workflow/controller/controller.go:678 +0x9e\nk8s.io/apimachinery/pkg/util/wait.BackoffUntil.func1(0x7f6812210978)\n\t/go/pkg/mod/k8s.io/[email protected]/pkg/util/wait/wait.go:155 +0x67\nk8s.io/apimachinery/pkg/util/wait.BackoffUntil(0x0, {0x226dbe0, 0xc003340a50}, 0x1, 0xc00043b4a0)\n\t/go/pkg/mod/k8s.io/[email protected]/pkg/util/wait/wait.go:156 +0xb6\nk8s.io/apimachinery/pkg/util/wait.JitterUntil(0x0, 0x3b9aca00, 0x0, 0x0, 0x0)\n\t/go/pkg/mod/k8s.io/[email protected]/pkg/util/wait/wait.go:133 +0x89\nk8s.io/apimachinery/pkg/util/wait.Until(0x0, 0x0, 0x0)\n\t/go/pkg/mod/k8s.io/[email protected]/pkg/util/wait/wait.go:90 +0x25\ncreated by github.com/argoproj/argo-workflows/v3/workflow/controller.(*WorkflowController).Run\n\t/go/src/github.com/argoproj/argo-workflows/workflow/controller/controller.go:294 +0x1a6c\n" workflow=test-workflow-parameters-1
time="2022-08-01T12:12:03.774Z" level=info msg="Updated phase  -> Error" namespace=siebren workflow=test-workflow-parameters-1
time="2022-08-01T12:12:03.774Z" level=info msg="Updated message  -> runtime error: invalid memory address or nil pointer dereference" namespace=siebren workflow=test-workflow-parameters-1
time="2022-08-01T12:12:03.774Z" level=info msg="Marking workflow completed" namespace=siebren workflow=test-workflow-parameters-1
time="2022-08-01T12:12:03.774Z" level=info msg="Checking daemoned children of " namespace=siebren workflow=test-workflow-parameters-1
time="2022-08-01T12:12:03.780Z" level=info msg="cleaning up pod" action=deletePod key=siebren/test-workflow-parameters-1-1340600742-agent/deletePod
time="2022-08-01T12:12:03.788Z" level=info msg="Workflow update successful" namespace=siebren phase=Error resourceVersion=164853863 workflow=test-workflow-parameters-1
time="2022-08-01T12:12:03.789Z" level=info msg="Queueing Error workflow siebren/test-workflow-parameters-1 for delete in 24h0m0s due to TTL"

Message from the maintainers:

Impacted by this bug? Give it a 👍. We prioritise the issues with the most 👍.

@smile-luobin
Copy link
Contributor

secretKeyRef is unsupported in valueFrom.

arguments:

    parameters:
    - name: foobar
      valueFrom:
        secretKeyRef:
          name: my-secret
          key: test

will be Unmarshaled as:

    parameters:
    - name: foobar
      valueFrom: {}

there is no validation if valueFrom=={} in func validateArgumentsValues:

if param.ValueFrom == nil && param.Value == nil {

@Siebjee
Copy link
Contributor Author

Siebjee commented Aug 4, 2022

But shouldn't the error be more explanatory :).

I didn't submit this issue because it's unsupported, but the error is not clear enough that it isn't supported. In fact it throws a "nil pointer". Which is bad :).

@smile-luobin
Copy link
Contributor

@Siebjee agree with you.

maybe we can do validation in func validateArgumentsValues argo-workflows/workflow/validate/validate.go, and return a more explanatory error if valueFrom=={}.

@alexec alexec added area/controller Controller issues, panics and removed triage labels Sep 5, 2022
@sarabala1979 sarabala1979 removed their assignment Sep 14, 2022
@sarabala1979 sarabala1979 added the P1 High priority. All bugs with >=5 thumbs up that aren’t P0, plus: Any other bugs deemed high priority label Sep 23, 2022
@sarabala1979
Copy link
Member

@smile-luobin Do you like to submit the PR?

@alexec
Copy link
Contributor

alexec commented Oct 10, 2022

To fix this, modify this block of code

From:

for _, param := range executionParameters.Parameters {

To:

	for _, param := range executionParameters.Parameters {
		if param.ValueFrom != nil && param.ValueFrom.ConfigMapKeyRef != nil {
			cmValue, err := common.GetConfigMapValue(woc.controller.configMapInformer, woc.wf.ObjectMeta.Namespace, param.ValueFrom.ConfigMapKeyRef.Name, param.ValueFrom.ConfigMapKeyRef.Key)
			if err != nil {
				return fmt.Errorf("failed to set global parameter %s from configmap with name %s and key %s: %w",
					param.Name, param.ValueFrom.ConfigMapKeyRef.Name, param.ValueFrom.ConfigMapKeyRef.Key, err)
			}
			woc.globalParams["workflow.parameters."+param.Name] = cmValue
		} else if param.Value != nil {
			woc.globalParams["workflow.parameters."+param.Name] = param.Value.String()
		} else {
			return fmt.Errorf("either value or valueFrom must be specified in order to set global parameter %s", 
                }
	}

This is a really easy fix. Would someone like to volunteer?

@alexec alexec added the solution/suggested A solution to the bug has been suggested. Someone needs to implement it. label Oct 10, 2022
alexec pushed a commit that referenced this issue Oct 11, 2022
juchaosong pushed a commit to juchaosong/argo-workflows that referenced this issue Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/controller Controller issues, panics P1 High priority. All bugs with >=5 thumbs up that aren’t P0, plus: Any other bugs deemed high priority solution/suggested A solution to the bug has been suggested. Someone needs to implement it. type/bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants