Skip to content

[BUG] The RestController always consumes content when handling real HTTP requests #638

@dbwiddis

Description

@dbwiddis

What is the bug?

The BaseRestHandler includes a check whether content (the REST body) has been consumed by an API, throwing an exception here if it does not do so. This exception is tested in OpenSearch in a few places and we relied on it here for multiple APIs:

  • Get Workflow
  • Delete Workflow
  • Get Workflow State
  • Deprovision Workflow
  • Get Workflow Step

The reason for this check was that including a body would still execute the requested action but then fail to provide a proper REST result to the user. For the Get APIs this was mostly harmless, but deleting or deprovisioning a workflow would have side effects not reported to the user.

Unfortunately, it appears that these unit tests which rely on the behavior of the BaseRestHandler do not take into account the fact that the RestController always consumes content here when a REST request arrives via the HTTP handler.

How can one reproduce the bug?

Query any of the above APIs with a body in the request, for example

localhost:9200/_plugins/_flow_framework/workflow/any_id_here
{}

The result is:

{
    "error": {
        "root_cause": [
            {
                "type": "illegal_state_exception",
                "reason": "Channel is already closed"
            }
        ],
        "type": "illegal_state_exception",
        "reason": "Channel is already closed"
    },
    "status": 500
}

What is the expected behavior?

As intended: a 400 response with the message "request [GET /_plugins/_flow_framework/workflow/{workflow_id}] does not support having a body"

As implemented elsewhere in OpenSearch: silently ignored

Do you have any additional context?

This behavior has existed for at least 5 years but is undocumented/confusing. I'll be submitting a bug on the OpenSearch side reporting this, but the ideal fix (not consuming content) would potentially be seriously backwards incompatble with many scripts developed in the past 5 years.

In the meantime, we should not be sending null back to the Base Rest Handler.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingv2.14.0

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions