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 handling enhancement: StringIndexOutOfBoundsException when executing task in k8s for malformed task arguments #4617

Closed
guoyiang opened this issue Jul 9, 2021 · 2 comments
Assignees
Labels
area/batch-task Belongs to batch and task type/bug Is a bug report
Milestone

Comments

@guoyiang
Copy link

guoyiang commented Jul 9, 2021

Description:
When executing a task (POST tasks/executions), if arguments has an extra space at the end, spring cloud dataflow may throw a StringIndexOutOfBoundsException. Server will respond with status code 500 and payload:

{"_embedded":{"errors":[{"message":"String index out of range: -1","logref":"StringIndexOutOfBoundsException","_links":{"self":{"href":"/"}}}]}}%

The stacktrace on spring cloud dataflow:

2021-07-09 14:46:43.043 ERROR 1 --- [nio-8080-exec-3] o.s.c.d.s.k.KubernetesTaskLauncher       : String index out of range: -1

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
        at java.lang.String.substring(String.java:1967)
        at org.springframework.cloud.deployer.spi.kubernetes.DefaultContainerFactory.lambda$createCommandArgs$0(DefaultContainerFactory.java:277)
        at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
        at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1384)
        at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
        at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
        at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
        at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566)
        at org.springframework.cloud.deployer.spi.kubernetes.DefaultContainerFactory.createCommandArgs(DefaultContainerFactory.java:278)
        at org.springframework.cloud.deployer.spi.kubernetes.DefaultContainerFactory.create(DefaultContainerFactory.java:102)
        at org.springframework.cloud.deployer.spi.kubernetes.AbstractKubernetesDeployer.createPodSpec(AbstractKubernetesDeployer.java:201)
        at org.springframework.cloud.deployer.spi.kubernetes.KubernetesTaskLauncher.launch(KubernetesTaskLauncher.java:238)
        at org.springframework.cloud.deployer.spi.kubernetes.KubernetesTaskLauncher.launch(KubernetesTaskLauncher.java:120)

Release versions:

{
  "versions": {
    "implementation": {
      "name": "spring-cloud-dataflow-server",
      "version": "2.7.1"
    },
    "core": {
      "name": "Spring Cloud Data Flow Core",
      "version": "2.7.1"
    },
    "dashboard": {
      "name": "Spring Cloud Dataflow UI",
      "version": "3.0.1"
    },
    "shell": {
      "name": "Spring Cloud Data Flow Shell",
      "version": "2.7.1",
      "url": "https://repo1.maven.org/maven2/org/springframework/cloud/spring-cloud-dataflow-shell/2.7.1/spring-cloud-dataflow-shell-2.7.1.jar"
    }
  },
  "features": {
    "streams": false,
    "tasks": true,
    "schedules": true,
    "monitoringDashboardType": "NONE"
  },
  "runtimeEnvironment": {
    "appDeployer": {
      "deployerImplementationVersion": null,
      "deployerName": null,
      "deployerSpiVersion": null,
      "javaVersion": null,
      "platformApiVersion": null,
      "platformClientVersion": null,
      "platformHostVersion": null,
      "platformSpecificInfo": {},
      "platformType": null,
      "springBootVersion": null,
      "springVersion": null
    },
    "taskLaunchers": [
      {
        "deployerImplementationVersion": "2.5.1",
        "deployerName": "KubernetesTaskLauncher",
        "deployerSpiVersion": "2.5.1",
        "javaVersion": "1.8.0_282",
        "platformApiVersion": "v1",
        "platformClientVersion": "unknown",
        "platformHostVersion": "unknown",
        "platformSpecificInfo": {
          "namespace": "dev",
          "master-url": "https://192.168.0.1:443/"
        },
        "platformType": "Kubernetes",
        "springBootVersion": "2.3.7.RELEASE",
        "springVersion": "5.2.12.RELEASE"
      }
    ]
  },
  "monitoringDashboardInfo": {
    "url": "",
    "source": "default-scdf-source",
    "refreshInterval": 15
  },
  "security": {
    "isAuthentication": false,
    "isAuthenticated": false,
    "username": null,
    "roles": []
  }
}

Steps to reproduce:

  1. Setup a task app & task definition in spring cloud dataflow on kubernetes platform
  2. Execute a task by calling API with a malformed argument, like the one below. Note the extra %20 at the end of arguments query param.
curl -X POST 'http://localhost:9393/tasks/executions?name=test&arguments=--a=b%20--c=d%20' -H 'Content-Type: application/json' 

Additional context:
It is caused when handling arguments in k8s deployer. It splits the arguments using space and then separate key/value using =. However the code doesn't handle the case when = is not present in each argument. Not too sure about the best approach to handle it, should we ignore such arguments, or return a validation error.
Though it's a caused by bad API integration, it would be great if a better message can be returned. It's not easy to figure out the cause without looking into stacktrace & source code.

Thanks for supporting it!

@github-actions github-actions bot added the status/need-triage Team needs to triage and take a first look label Jul 9, 2021
@sabbyanandan
Copy link
Contributor

Thanks for the thorough write-up, @guoyiang. If you've cycles, please feel free to submit a PR to gracefully handle this workflow. We can pair to get this handled and bring it to the desired state.

@sabbyanandan sabbyanandan added type/help-needed Calling help and removed status/need-triage Team needs to triage and take a first look labels Jul 14, 2021
@markpollack markpollack removed the type/help-needed Calling help label Sep 29, 2022
@markpollack markpollack added this to the 2.10.0-M3 milestone Sep 29, 2022
@markpollack markpollack added the type/bug Is a bug report label Sep 29, 2022
@markpollack markpollack modified the milestones: 2.10.0-M3, 2.10.0-RC1 Oct 7, 2022
@markpollack markpollack added the area/batch-task Belongs to batch and task label Oct 7, 2022
@onobc onobc modified the milestones: 2.10.0-RC1, 2.10.0-RC2 Oct 21, 2022
@onobc onobc self-assigned this Nov 15, 2022
@cppwfs
Copy link
Contributor

cppwfs commented Nov 15, 2022

This issue is resolved via 2.10. Please retest. Thank you for reporting!

@cppwfs cppwfs closed this as completed Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/batch-task Belongs to batch and task type/bug Is a bug report
Projects
None yet
Development

No branches or pull requests

5 participants