Skip to content

Fix PPL REST handler returning 500 for OpenSearchRejectedExecutionException#5512

Draft
aravindsagar wants to merge 1 commit into
opensearch-project:mainfrom
aravindsagar:fix/ppl-rejected-execution-status
Draft

Fix PPL REST handler returning 500 for OpenSearchRejectedExecutionException#5512
aravindsagar wants to merge 1 commit into
opensearch-project:mainfrom
aravindsagar:fix/ppl-rejected-execution-status

Conversation

@aravindsagar
Copy link
Copy Markdown

Description

Description

RestPPLQueryAction.getRawErrorCode() has a hardcoded return 500 fallback for exceptions that don't match OpenSearchException or the known client-error list. OpenSearchRejectedExecutionException extends RejectedExecutionExceptionRuntimeException (not OpenSearchException), so it always fell through to the 500 path — even though OpenSearch core's ExceptionsHelper.status() already maps it to TOO_MANY_REQUESTS (429).

This affects any backend that throws OpenSearchRejectedExecutionException through the PPL query path (e.g., admission control rejections from the analytics engine under memory pressure).

Changes

  • Replace return 500 with return ExceptionsHelper.status(ex).getStatus() — delegates to the same mapping used by DSL _search and the rest of OpenSearch
  • Remove a stale comment about future ErrorCode-based mapping
  • Add RestPPLQueryActionTest with unit tests covering the key exception→status mappings

Testing

Unit tests (all pass):

  • testRejectedExecutionReturns429 — the primary fix scenario
  • testOpenSearchStatusExceptionPreservesStatus — verifies OpenSearchException path still works (404)
  • testIndexNotFoundReturns404 — IndexNotFoundException (extends OpenSearchException)
  • testSyntaxCheckExceptionReturns400 — client error path
  • testQueryEngineExceptionReturns400 — client error path
  • testGenericRuntimeExceptionReturns500 — unknown exceptions still return 500

Full plugin test suite: ./gradlew :opensearch-sql-plugin:test — all existing tests pass.

Manual end-to-end verification (local single-node cluster with DataFusion analytics backend):

  1. Injected a Rust-side memory admission rejection (admission_rejected_error) in the native query engine
  2. NativeErrorConverter correctly converted the native error string to OpenSearchRejectedExecutionException
  3. Before fix: PPL /_plugins/_ppl returned HTTP 500 / INTERNAL_SERVER_ERROR
  4. After fix: PPL /_plugins/_ppl returned HTTP 429 / TOO_MANY_REQUESTS
  5. DSL /_search path confirmed returning 429 both before and after (it already uses ExceptionsHelper.status())

Related Issues

Resolves #[Issue number to be closed when this PR is merged]

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • New PPL command checklist all confirmed.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff or -s.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

…eption

RestPPLQueryAction.getRawErrorCode() had a hardcoded `return 500` fallback for
exceptions that aren't OpenSearchException or known client errors. This meant
OpenSearchRejectedExecutionException (which extends RejectedExecutionException,
not OpenSearchException) always surfaced as HTTP 500 instead of 429.

Replace the hardcoded fallback with ExceptionsHelper.status(ex).getStatus(),
which already handles OpenSearchRejectedExecutionException -> TOO_MANY_REQUESTS
mapping in OpenSearch core.

Signed-off-by: Aravind Sagar <sagarara@amazon.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 2026

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ No major issues detected

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

Successfully merging this pull request may close these issues.

1 participant