Skip to content

Conversation

@eric-wang-1990
Copy link
Contributor

Summary

Reordered HTTP delegating handlers in DatabricksConnection to ensure RetryHttpHandler processes responses before ThriftErrorMessageHandler throws exceptions. This fixes a bug where 503 Service Unavailable responses with Retry-After headers (e.g., during cluster auto-start) were not being retried.

Problem

Previously, the handler chain had ThriftErrorMessageHandler as the innermost handler:

ThriftErrorMessageHandler (inner) → RetryHttpHandler (outer) → Network

This caused ThriftErrorMessageHandler to process error responses first and throw exceptions immediately, preventing RetryHttpHandler from retrying 503 responses during cluster auto-start scenarios.

Solution

Reordered the chain so RetryHttpHandler is inside ThriftErrorMessageHandler:

RetryHttpHandler (inner) → ThriftErrorMessageHandler (outer) → Network

Now responses flow: Network → RetryHttpHandler → ThriftErrorMessageHandler

With this order:

  1. RetryHttpHandler processes 503 responses first and retries them according to Retry-After headers
  2. Only after all retries are exhausted does ThriftErrorMessageHandler throw exceptions with Thrift error messages

Changes

  • Reordered handlers in DatabricksConnection.CreateHttpHandler()
  • Added comprehensive documentation explaining handler chain execution order and why it matters
  • Added cross-references in RetryHttpHandlerTest and ThriftErrorMessageHandlerTest pointing to the production code

Test Plan

  • ✅ All existing unit tests pass:
    • ThriftErrorMessageHandlerTest: 11/11 tests pass
    • RetryHttpHandlerTest: 14/14 tests pass
  • The fix will be validated in E2E tests when connecting to Databricks clusters that need auto-start

Related Issues

Fixes cluster auto-start retry issues where 503 responses with Retry-After headers were not being retried.

…ry before exception

## Summary
Reordered HTTP delegating handlers in DatabricksConnection to ensure RetryHttpHandler
processes responses before ThriftErrorMessageHandler throws exceptions. This fixes a bug
where 503 Service Unavailable responses with Retry-After headers (e.g., during cluster
auto-start) were not being retried.

## Changes
- Moved ThriftErrorMessageHandler to be OUTSIDE (farther from network) RetryHttpHandler
- Added comprehensive documentation explaining handler chain execution order
- Added cross-references in unit tests pointing to the production code documentation

## Why This Order Matters
HTTP delegating handlers execute from outermost to innermost on requests, and innermost
to outermost on responses. With the corrected order:

1. RetryHttpHandler (inner) processes 503 responses first and retries them
2. Only after all retries are exhausted does ThriftErrorMessageHandler (outer) throw
   exceptions with Thrift error messages

Previous incorrect order had ThriftErrorMessageHandler as the innermost handler, causing
it to throw exceptions immediately without allowing retries.

## Test Plan
- All existing unit tests pass (11/11 for ThriftErrorMessageHandler, 14/14 for RetryHttpHandler)
- The fix will be validated in E2E tests when connecting to Databricks clusters that need auto-start

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@github-actions github-actions bot added this to the ADBC Libraries 21 milestone Oct 16, 2025
@eric-wang-1990 eric-wang-1990 changed the title fix(csharp/databricks): Fix HTTP handler chain ordering to enable retry before exception fix(csharp/src/drivers/databricks): Fix HTTP handler chain ordering to enable retry before exception Oct 16, 2025
@eric-wang-1990 eric-wang-1990 changed the title fix(csharp/src/drivers/databricks): Fix HTTP handler chain ordering to enable retry before exception fix( csharp/src/Drivers/Databricks): Fix HTTP handler chain ordering to enable retry before exception Oct 16, 2025
@eric-wang-1990 eric-wang-1990 changed the title fix( csharp/src/Drivers/Databricks): Fix HTTP handler chain ordering to enable retry before exception fix(csharp/src/Drivers/Databricks): Fix HTTP handler chain ordering to enable retry before exception Oct 16, 2025
baseAuthHandler = new ThriftErrorMessageHandler(baseAuthHandler);

// Add tracing handler to propagate W3C trace context if enabled
// IMPORTANT: Handler Order Matters!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@CurtHagenlocher CurtHagenlocher merged commit 46a63a9 into apache:main Oct 16, 2025
6 of 10 checks passed
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.

2 participants