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

[BUG] Deprovision workflow returns 500 error when workflow ID not found #810

Closed
dbwiddis opened this issue Jul 26, 2024 · 0 comments · Fixed by #811
Closed

[BUG] Deprovision workflow returns 500 error when workflow ID not found #810

dbwiddis opened this issue Jul 26, 2024 · 0 comments · Fixed by #811
Labels
bug Something isn't working v2.16.0 Issues targeting release v2.16.0

Comments

@dbwiddis
Copy link
Member

What is the bug?

When attempting to deprovision a workflow with a document id that does not exist, a 500 (INTERNAL_SERVER_ERROR) response is given.

How can one reproduce the bug?

  1. Provision a workflow.
  2. Delete the document from the state index with that workflow ID.
  3. Attempt to deprovision the workflow.
[2024-07-25T19:28:08,429][ERROR][o.o.f.t.DeprovisionWorkflowTransportAction] [eb67737de9cbbf02c477726fc8ebf46d] Failed to get workflow state for workflow 3Uqby5ABgrORC4V3o7kx
org.opensearch.flowframework.exception.FlowFrameworkException: Fail to find workflow 3Uqby5ABgrORC4V3o7kx

<trace truncated>

[2024-07-25T19:28:08,429][INFO ][c.a.c.e.logger           ] [eb67737de9cbbf02c477726fc8ebf46d] POST /_plugins/_flow_framework/workflow/3Uqby5ABgrORC4V3o7kx/_deprovision - 500 INTERNAL_SERVER_ERROR 74 2

What is the expected behavior?

The wrong workflow ID should return a 400-series error, either not found, or bad request.

Do you have any additional context?

The error is automatically wrapped from the exception thrown in the Get Workflow State action

client.execute(GetWorkflowStateAction.INSTANCE, getStateRequest, ActionListener.wrap(response -> {
context.restore();
Set<String> deleteAllowedResources = Strings.tokenizeByCommaToSet(allowDelete);
// Retrieve resources from workflow state and deprovision
threadPool.executor(DEPROVISION_WORKFLOW_THREAD_POOL)
.execute(
() -> executeDeprovisionSequence(
workflowId,
response.getWorkflowState().resourcesCreated(),
deleteAllowedResources,
listener
)
);
}, exception -> {
String errorMessage = "Failed to get workflow state for workflow " + workflowId;
logger.error(errorMessage, exception);
listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(exception)));
}));

That should be using this workflow state 404 error:

listener.onFailure(new FlowFrameworkException("Fail to find workflow status of " + workflowId, RestStatus.NOT_FOUND));

This exception is then passed to ExceptionsHelper.status() which does not understand the FlowFrameworkException type.

Best fix is to change FlowFrameworkException to extend OpenSearchException and override status() so we can hit this line:

            if (t instanceof OpenSearchException) {
                return ((OpenSearchException) t).status();

See code for OpenSearchStatusException and adapt.

@dbwiddis dbwiddis added bug Something isn't working untriaged labels Jul 26, 2024
@dbwiddis dbwiddis added v2.16.0 Issues targeting release v2.16.0 and removed untriaged labels Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v2.16.0 Issues targeting release v2.16.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant