Skip to content

Improve backend fallback logic for unknown queryId handling #703

@talh3747

Description

@talh3747

Problem

In RoutingManager.findBackendForUnknownQueryId(), after checking all backends by issuing HEAD requests, the fallback logic is hardcoded to use the first active backend with routing_group = 'adhoc':

gatewayBackendManager.getActiveAdhocBackends().get(0).getProxyTo()

This breaks in trino gateway environments where no backend is designated with routing_group = 'adhoc', because:

  • getActiveAdhocBackends() executes:

    SELECT * FROM gateway_backend WHERE active = true AND routing_group = 'adhoc'
  • If no row matches, the results list is empty → .get(0) throws IndexOutOfBoundsException, causing a 500 Internal Server Error for /v1/query/{nonexistent-id} requests.

Proposed fix

Modify the fallback logic to be more robust and generic:

  • After failing to locate a backend by query ID, select fallback from any active backend, not just adhoc.

This ensures:

  • No crash even if no adhoc routing_group exists
  • Consistent behavior across environments

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions