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

Throw errors when job.complete is given invalid data #247

Open
TylerHAtkinson opened this issue Sep 16, 2024 · 3 comments
Open

Throw errors when job.complete is given invalid data #247

TylerHAtkinson opened this issue Sep 16, 2024 · 3 comments
Assignees

Comments

@TylerHAtkinson
Copy link

SDK Component

Zeebe

Expected Behavior

When passing an array of data to job.complete, I would expect an error to be thrown since zeebe doesn't seem to be able to properly deal with arrays.

Current Behavior

Possibly related to: #236
Currently passing an array of data to job.complete (job.complete([{ var1: 1 }])) does not throw an error, and the token is stuck on that task

Possible Solution

In parseVariablesAndCustomHeadersToJSON, add

if(Array.isArray(response.variables)) {
  throw new Error('Unable to parse Array into variables'); //Or something like that
}

Also if there's any other values that would cause this behavior, it would be nice to have those explicitly thrown

Steps to Reproduce

When handling a ZeebeJob, pass an array of data into job.complete

  • job.complete([{ var1: 1 }] as any)

Notice that the token is stuck with no incidents reported, and no errors thrown

Context (Environment)

I know the typing for complete technically doesn't allow arrays, due to a type assertion we ended up accidentally passing an array. While this was easy to fix, it was difficult to diagnose the issue since from adding console.logs it seemed like everything ran successfully

@jwulf jwulf self-assigned this Sep 16, 2024
@jwulf
Copy link
Member

jwulf commented Sep 16, 2024

Thanks for reporting this.

Hmmmm... this is a very strange behaviour, and I don't know that a run-time type guard here is the best place to address this in the system.

I would expect that if no error is thrown by the gRPC API call to Zeebe that the CompleteJob operation completed successfully.

I tested this scenario, and I see what you report: the gRPC API throws no error, the process does not throw an incident and the job is not completed. The job is sent for a retry, but because it doesn't fail on the client, no retry decrement occurs (retry decrement is the responsibility of the client making the FailJob RPC call).

Thus, the job goes into an infinite retry loop.

I will check with the Zeebe engineering team. I have a vague memory of this coming up a few years ago. Let me look into it.

@jwulf
Copy link
Member

jwulf commented Sep 16, 2024

We'll guard against it in the client immediately - I don't know at what point they'll be able to re-engineer the API.

The new REST API endpoint for completing a job (in 8.6) throws a 400 if you try to post an array to it.

@jwulf
Copy link
Member

jwulf commented Sep 17, 2024

stringifyVariables is the function that needs the guard. That one JSON stringifies the variables for a request to the gateway, and is called from the ZBClient completeJob method - which is how the worker completes jobs.

The parseVariablesAndCustomHeadersToJSON function is used for parsing responses from the gateway from stringified JSON to JS objects.

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

No branches or pull requests

2 participants