Skip to content

Fix invalid AuthMech crashing with Recursive update / StackOverflowError - #1558

Closed
sreekanth-db wants to merge 2 commits into
databricks:mainfrom
sreekanth-db:fix/invalid-authmech-fail-fast
Closed

sreekanth-db wants to merge 2 commits into
databricks:mainfrom
sreekanth-db:fix/invalid-authmech-fail-fast

Conversation

@sreekanth-db

Copy link
Copy Markdown
Collaborator

Summary

  • Connecting with an unsupported AuthMech (e.g. AuthMech=99) intermittently failed with an internal IllegalStateException: Recursive update or a StackOverflowError on both the SEA and Thrift paths, instead of a clean validation error.
  • Root cause: AuthMech.parseAuthMech throws during ClientConfigurator construction, which runs inside DatabricksClientConfiguratorManager.getConfigurator's ConcurrentHashMap.computeIfAbsent. The exception's constructor emits a telemetry failure log, whose feature-flag refresh re-enters getConfigurator for the same connectionUuid → a reentrant computeIfAbsent → Recursive update (or, depending on timing, StackOverflowError).
  • Fix: validate AuthMech at connect time in DatabricksConnectionContext.parse() (via ValidationUtil.validateInputProperties → new validateAuthMech), before the configurator machinery runs. Unsupported values are now rejected deterministically with a DatabricksValidationException (SQLState=INPUT_VALIDATION_ERROR).
  • A pure, side-effect-free AuthMech.fromValue(int) lookup is introduced as the single source of truth for supported values (3=PAT, 11=OAuth); parseAuthMech delegates to it, so adding a new AuthMech is a one-line change. parseAuthMech's behavior, exception type, and messages are unchanged.

Test plan

  • New unit tests ValidationUtilTest#testValidateAuthMech_*: supported values (3, 11, omitted) pass; unsupported/non-integer/empty throw INPUT_VALIDATION_ERROR.
  • New unit test DatabricksConnectionContextTest#parse_rejectsUnsupportedAuthMech_withInputValidationError.
  • Existing AuthFlowParsing and full ValidationUtilTest (47) / DatabricksConnectionContextTest (145) suites pass.
  • Manual repro against a live warehouse: AuthMech=99 went from IllegalStateException: Recursive update (5/5 attempts on both SEA and Thrift) to a clean DatabricksValidationException / INPUT_VALIDATION_ERROR (5/5 on both transports).

Connecting with an unsupported AuthMech (e.g. AuthMech=99) intermittently
crashed with an internal IllegalStateException: Recursive update or a
StackOverflowError on both SEA and Thrift, instead of a clean validation error.

The value was detected deep inside ClientConfigurator construction, which runs
inside getConfigurator's ConcurrentHashMap.computeIfAbsent; the failure fired a
telemetry log whose feature-flag refresh re-entered getConfigurator for the same
connectionUuid, causing a reentrant computeIfAbsent.

Validate AuthMech at connect time (DatabricksConnectionContext.parse ->
ValidationUtil.validateInputProperties) before the configurator machinery runs,
rejecting unsupported values deterministically with a DatabricksValidationException
(SQLState=INPUT_VALIDATION_ERROR). A pure AuthMech.fromValue lookup is the single
source of truth for supported values.

Signed-off-by: Sreekanth Vadigi <[email protected]>
…h-fail-fast

Signed-off-by: Sreekanth Vadigi <[email protected]>

# Conflicts:
#	NEXT_CHANGELOG.md
@sreekanth-db

Copy link
Copy Markdown
Collaborator Author

Closing in favor of a same-repo PR. Fork PRs cannot access INTEGRATION_TEST_APP_* secrets, so the required JDBC Integration Tests check never gets reported (Expected — Waiting for status to be reported). Recreating from databricks/databricks-jdbc:fix/invalid-authmech-fail-fast.

sreekanth-db added a commit that referenced this pull request Jul 29, 2026
…ror (#1586)

## Summary
- Connecting with an unsupported `AuthMech` (e.g. `AuthMech=99`)
intermittently failed with an internal `IllegalStateException: Recursive
update` or a `StackOverflowError` on both the SEA and Thrift paths,
instead of a clean validation error.
- Root cause: `AuthMech.parseAuthMech` throws during
`ClientConfigurator` construction, which runs inside
`DatabricksClientConfiguratorManager.getConfigurator`'s
`ConcurrentHashMap.computeIfAbsent`. The exception's constructor emits a
telemetry failure log, whose feature-flag refresh re-enters
`getConfigurator` for the **same** `connectionUuid` → a reentrant
`computeIfAbsent` → `Recursive update` (or, depending on timing,
`StackOverflowError`).
- Fix: validate `AuthMech` at connect time in
`DatabricksConnectionContext.parse()` (via
`ValidationUtil.validateInputProperties` → new `validateAuthMech`),
**before** the configurator machinery runs. Unsupported values are now
rejected deterministically with a `DatabricksValidationException`
(`SQLState=INPUT_VALIDATION_ERROR`).
- A pure, side-effect-free `AuthMech.fromValue(int)` lookup is
introduced as the single source of truth for supported values (`3`=PAT,
`11`=OAuth); `parseAuthMech` delegates to it, so adding a new AuthMech
is a one-line change. `parseAuthMech`'s behavior, exception type, and
messages are unchanged.

Replaces fork PR #1558 (same-repo so required JDBC Integration Tests can
be reported).

## Test plan
- [x] New unit tests `ValidationUtilTest#testValidateAuthMech_*`:
supported values (`3`, `11`, omitted) pass;
unsupported/non-integer/empty throw `INPUT_VALIDATION_ERROR`.
- [x] New unit test
`DatabricksConnectionContextTest#parse_rejectsUnsupportedAuthMech_withInputValidationError`.
- [x] Existing `AuthFlowParsing` and full `ValidationUtilTest` (47) /
`DatabricksConnectionContextTest` (145) suites pass.
- [x] Manual repro against a live warehouse: `AuthMech=99` went from
`IllegalStateException: Recursive update` (5/5 attempts on both SEA and
Thrift) to a clean `DatabricksValidationException` /
`INPUT_VALIDATION_ERROR` (5/5 on both transports).

Signed-off-by: Sreekanth Vadigi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants