Skip to content

[Server] Return a general error when the server's storage or STS calls fail - #2176

Merged
yili-db merged 5 commits into
unitycatalog:mainfrom
yili-db:stack/storage_errors
Nov 13, 2026
Merged

yili-db merged 5 commits into
unitycatalog:mainfrom
yili-db:stack/storage_errors

Conversation

@yili-db

@yili-db yili-db commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

🥞 Stacked PR

Use this link to review incremental changes.


Description of changes

The server's own AWS SDK calls (S3, STS) put the storage's error text, which can name its endpoint, into error responses. They now return a general error.

  • StorageExceptions: an SdkException in the cause chain becomes INTERNAL "Failed to access storage.", in BaseExceptionHandler and TransactionManager
    • the walk stops at a BaseException, which already says what callers get
    • the cause is kept, so the handler logs it once with the response
  • A failed AssumeRole returns INTERNAL "Failed to vend temporary storage credentials.", with the STS exception as its cause
  • A storage cleanup that fails this way records its error code and its cause's class, such as INTERNAL caused by StsException, still without any message text

Behavior change: the status and error code of these failures are unchanged (INTERNAL, HTTP 500), but the message no longer includes the storage or STS text. A storage failure anywhere in the cause chain now takes precedence over the INVALID_ARGUMENT, UNAUTHENTICATED and database error-code mappings, so an IllegalArgumentException that wraps one is reported as INTERNAL. BaseExceptions the server builds itself, such as the region errors in FileOperationsImpl, are unaffected. Azure and GCS failures are not covered.

Note: independent of the S3-compatible storage stack (#2170 to #2175, then #2169). Once this merges, #2172 adds a test that relies on this error handling.

Tests: handler tests for the UC, Iceberg and Delta APIs; TransactionManagerTest; CloudCredentialVendorTest.

PR Checklist

  • A description of the changes is added to the description of this PR.
  • If there is a related issue, make sure it is linked to this PR.
  • If you've fixed a bug or added code that should be tested, add tests!
  • If you've added or modified a feature, documentation in docs is updated

This pull request and its description were written by Isaac.

@yili-db

yili-db commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

/review

@yili-db
yili-db force-pushed the stack/storage_errors branch from 675f13e to cd9953c Compare November 11, 2026 23:39
@yili-db

yili-db commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

/review

@yili-db
yili-db marked this pull request as ready for review November 11, 2026 23:56
@yili-db
yili-db requested a review from shba24 November 11, 2026 23:56
@yili-db
yili-db force-pushed the stack/storage_errors branch from cd9953c to 01114df Compare November 12, 2026 03:19
@yili-db

yili-db commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

/review

@shba24 shba24 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks Yi, this closes a real leak. I ran the three handlers on main and on this head with an S3 403, an S3 503 (SlowDown), an STS 403 and a client-side connect failure: on main the body carried storage.example.com and the role ARN, and here it says only "Failed to access storage.". Nothing below blocks merging.

PR description (should fix, small): the "Behavior change" paragraph says these failures now map to INTERNAL (HTTP 500), including AccessDenied, NoSuchBucket and throttling. They already did on main: BaseExceptionHandler.toBaseException fell through to wrapException(ErrorCode.INTERNAL, cause), and TransactionManager to DatabaseErrors.errorCode(...).orElse(INTERNAL). The same local run gave identical statuses before and after. How about:

Behavior change: the status and error code of these failures are unchanged (INTERNAL, HTTP 500), but the message no longer includes the storage or STS text.

Not a blocker, cleanup error column: StorageCleanupWorker.safeError stores exception.getClass().getSimpleName() in the task's lastError. Cleanup of an S3 location vends credentials through FileOperationsImpl.getCleanupFileIO -> serverFileIOConfig -> vendCredential, so with the new STS wrapper a failed AssumeRole is now recorded as "Storage cleanup failed: BaseException" instead of "... StsException". I confirmed it with a scratch test in StorageCleanupWorkerTest. The WARN log still has the full chain, so only the stored summary loses detail. If you'd like to keep it, one option that still carries no message text:

private static String safeError(Exception exception) {
  String name =
      exception instanceof BaseException be && exception.getCause() != null
          ? be.getErrorCode() + " caused by " + exception.getCause().getClass().getSimpleName()
          : exception.getClass().getSimpleName();
  return "Storage cleanup failed: " + name;
}

Feel free to take or skip it, or leave it for later.

The inline comments are all small: one test assertion and a few nits.

"Error executing operation",
false))
.isInstanceOf(BaseException.class)
.hasMessage("Failed to access storage.")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could this also check that the storage failure is kept as the cause? On this path the handler logs the general BaseException itself, so its cause is the only place the S3 detail survives. I tried dropping it (passing null as the cause in toGeneralError), and all 64 tests in ErrorCodeTest, TransactionManagerTest and CloudCredentialVendorTest still passed. Adding this line makes this test fail on that change and pass on the current code:

Suggested change
.hasMessage("Failed to access storage.")
.hasMessage("Failed to access storage.")
.hasCause(storageFailure)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

+1

* @return an INTERNAL error that carries no storage detail in its message
*/
public static BaseException toGeneralError(Throwable e) {
BaseException error = new BaseException(ErrorCode.INTERNAL, GENERAL_MESSAGE, e);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit (not a blocker): BaseExceptionHandler.wrapException(ErrorCode, String, Throwable) is protected static in the same package and does exactly this, so the empty-trace rule could stay in one place. All 64 tests in the three touched classes pass with:

  public static BaseException toGeneralError(Throwable e) {
    return BaseExceptionHandler.wrapException(ErrorCode.INTERNAL, GENERAL_MESSAGE, e);
  }

*/
public final class StorageExceptions {
/** The message callers get when the server's storage access fails. */
public static final String GENERAL_MESSAGE = "Failed to access storage.";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit (not a blocker): the only use outside this class is ErrorCodeTest. If that test checks the literal "Failed to access storage.", as TransactionManagerTest already does, this can be private, and a change to the message would break the tests instead of moving them along with it.


/**
* Failures of the server's own AWS SDK calls, such as to S3 or STS. Their messages come from the
* storage or STS service and can name its endpoint, so callers get a general error. The failure is

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit (not a blocker): two small accuracy points. An SdkClientException's message is written by the SDK client, not the service (the tests use "Connect to storage.example.com failed"). And the server's own STS call is now wrapped in AwsCredentialGenerator, so the walk stops at that BaseException and never reaches here. Maybe something like:

Failures of the server's own AWS SDK calls, such as to S3. Their messages, from the SDK or the storage service, can name its endpoint, so callers get a general error.

try {
return stsClient.assumeRole(roleRequestBuilder.build()).credentials();
} catch (SdkException e) {
// The STS response is the cause, which the exception handler logs; the caller gets a

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit (not a blocker): SdkException also covers client-side failures (DNS, connect timeout, credential resolution), which have no STS response. Also, without this catch the handler would still map the StsException to INTERNAL "Failed to access storage.", so this catch is there for the more specific message. Saying so would stop someone from removing it as redundant. How about:

        // The SDK failure is the cause, which the exception handler logs. This names the failed
        // step more precisely than StorageExceptions' general message.

@shba24

shba24 commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Local AI review run on cd9953c (shba24)

Ran locally before reviewing:

  • Reviewer roles: the repo's roles from .github/omnigent/reviewer (uc-domain, maintainer-claude, architecture, test-coverage, docs), Claude Opus. maintainer-codex was not run.
  • Extra agents: test-coverage, comment-accuracy, error-handling, type-design and simplification agents.
  • Disprove gate: two blind disprovers, then local tests against main (303f05f) and this head.
Outcome Findings
Posted in the review above description says status changed (it did not); cause not asserted in TransactionManagerTest; cleanup lastError now BaseException; toGeneralError duplicates wrapException; GENERAL_MESSAGE public for a test; two comment-accuracy nits
Disproved IAE wrapping an SDK failure going from 400 to 500 (real in a test, but no server path builds one); Iceberg-typed exceptions bypassing the storage check
Judged too minor to post naming, cause-depth cap, 503 for throttling (pre-existing), test structure, package placement

Tests in the touched classes pass locally (62/62); javafmt and checkstyle are clean.

@yili-db
yili-db force-pushed the stack/storage_errors branch from 01114df to 5c86f27 Compare November 12, 2026 07:01
@yili-db

yili-db commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

/review

1 similar comment
@yili-db

yili-db commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

/review

@timothyw553

Copy link
Copy Markdown
Collaborator

hi @yili-db i'll take a look.

@timothyw553 timothyw553 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

no production code change issues. I just left some comments on the tests. Approval remains upon addressing.

Comment on lines +138 to +139
.hasMessage("Failed to vend temporary storage credentials.")
.hasCauseInstanceOf(StsException.class)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

is this using real STS client or mocked? if it's using real then what would happen if we got some kind of real STS connection error like SdkClientException? should we change to mock?

Comment on lines +157 to +159
for (Throwable failure :
List.of(storage, new UncheckedIOException(new IOException("read failed", storage)))) {
for (BaseExceptionHandler handler :

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

an IllegalArgumentException can wrap an SDK error.

@yili-db

yili-db commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

/review

yili-db and others added 5 commits November 12, 2026 19:46
…s fail

- Add `StorageExceptions`: an `SdkException` in the cause chain becomes `INTERNAL` "Failed to access storage."
  - applied in `BaseExceptionHandler` and `TransactionManager`
  - the cause is kept, so the handler logs it with the response
- `StsAwsCredentialGenerator` logs a failed `AssumeRole` and throws `INTERNAL` "Failed to vend temporary storage credentials."
- Behavior change for AWS: callers no longer see the storage or STS message text

Signed-off-by: Yi Li <[email protected]>
Co-authored-by: Isaac <[email protected]>
- `StsAwsCredentialGenerator` keeps the STS exception as the cause and no longer logs it itself; the exception handler logs it once
- `StorageExceptions`:
  - the walk over causes stops at a `BaseException`, which already says what callers get
  - a depth bound replaces the self-cause check, which could never fire
  - the general error has an empty stack trace, as `wrapException` does, so error responses show the cause's trace
  - Javadoc says it covers AWS SDK failures (S3, STS), not Azure or GCS
- `ErrorCodeTest`: the UC, Iceberg and Delta handlers report a direct and a wrapped SDK failure as HTTP 500 with the general message

Signed-off-by: Yi Li <[email protected]>
Co-authored-by: Isaac <[email protected]>
- `StorageCleanupWorker` records a general error with its error code and its cause's class, such as `INTERNAL caused by StsException`, still without any message text
- `TransactionManagerTest` checks that the storage failure is kept as the cause
- `StorageExceptions.toGeneralError` uses `BaseExceptionHandler.wrapException`, and its message is private; `ErrorCodeTest` checks the literal
- Javadoc and comments: the SDK, not only the service, writes these messages, and the STS catch names the failed step more precisely than the general message

Signed-off-by: Yi Li <[email protected]>
Co-authored-by: Isaac <[email protected]>
- `CloudCredentialVendorTest` mocks the STS client instead of calling AWS STS with fake keys, and checks both an STS error response and a failure to reach STS
- `ErrorCodeTest`: an `IllegalArgumentException` that wraps an SDK failure is reported as the general error, not `INVALID_ARGUMENT`

Signed-off-by: Yi Li <[email protected]>
Co-authored-by: Isaac <[email protected]>
@yili-db
yili-db force-pushed the stack/storage_errors branch from 5ee9917 to 69506e0 Compare November 12, 2026 23:23
@yili-db

yili-db commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

/review

@yili-db
yili-db merged commit 3e3cfc4 into unitycatalog:main Nov 13, 2026
22 of 23 checks passed
yili-db added a commit that referenced this pull request Nov 17, 2026
## 🥞 Stacked PR
Use this
[link](https://github.com/unitycatalog/unitycatalog/pull/2172/files/1c90863a0a328f0bec36232d3518c4fd65b9b6b6..7578d349b6dfd243ba229f147bf2046ece7ffc54)
to review incremental changes.
-
[stack/s3compat_spec](#2170)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2170/files)]
[MERGED]
-
[stack/s3compat_credentials](#2171)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2171/files)]
-
[**stack/s3compat_vending**](#2172)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2172/files/1c90863a0a328f0bec36232d3518c4fd65b9b6b6..7578d349b6dfd243ba229f147bf2046ece7ffc54)]
← _this PR_
-
[stack/s3compat_hadoop_cli](#2173)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2173/files/7578d349b6dfd243ba229f147bf2046ece7ffc54..df3d6a134500556e4368352bffde8d4099c20478)]
-
[stack/s3compat_test_storage](#2174)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2174/files/df3d6a134500556e4368352bffde8d4099c20478..c43d8b01648e305615c27110fd892fd631924830)]
-
[stack/s3compat_helm_key](#2175)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2175/files/c43d8b01648e305615c27110fd892fd631924830..1262f181a18b28b9c856e1367cc6301b57bd4fbf)]
-
[stack/s3compat_credentials_text](#2169)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2169/files/1262f181a18b28b9c856e1367cc6301b57bd4fbf..b7b769051dd8fccbc7578458ad68f1bd642adf93)]

---------
Part of a stack adding experimental S3-compatible storage (MinIO, Ceph,
SeaweedFS, RustFS, Garage): #2170 (merged) to #2175, then #2169. Each PR
builds on the one before it; the files changed since the previous PR are
under the link above.

**Description of changes**

Credential vending for paths whose external location uses an
`s3_compatible` credential.

- With `assume_role`: `AssumeRole` at `sts_endpoint`, or at
`s3_endpoint` when none is set, signed with the credential's key pair,
with the session policy scoped to the path (without the KMS statement)
  - each AssumeRole call, with retries, is capped at 30 seconds
- on shutdown, after the server drained its requests, it closes every
STS client the AWS vendor built (`AwsCredentialVendor` and
`CloudCredentialVendor` are `AutoCloseable`): the master role's and each
bucket's at once, and a vend that would build one of those after the
close gets `UNAVAILABLE`; the S3-compatible ones once the calls using
them finish, and a call after the close uses a client of its own
- a failed client close, of a shared or a one-off client, is logged
rather than replacing a call's result
- an STS client without configured keys gets a
`DefaultCredentialsProvider` of its own, since closing a client closes
its provider, and `DefaultCredentialsProvider.create()` returns one
shared by every AWS client in the JVM
- one STS client per STS endpoint and signing region, holding no keys:
each `AssumeRole` is signed with the key pair of the credential version
the request read, so updates close no client in use and no client keeps
a key pair; at most 100 are kept, and an evicted one closes after the
calls using it (`SharedStsGenerator`); a call whose client was evicted
twice uses one of its own
- Without `assume_role`,
`server.s3-compatible-storage.static-key-vending` decides what clients
get:
- `endpoint-only` (default): the endpoint and region, no keys; engines
use their own
- `static-key`: the key pair, with an hour after which clients fetch
again
- the server's own access always gets the key pair; the secret is loaded
only when keys are returned
- `S3BucketRegions` reads the bucket's region from an anonymous
`HeadBucket`, one lookup per bucket at a time, and caches a reported
region
- otherwise the default `us-east-1` is used, and the storage is asked
again after 30 seconds on a failure, or 5 minutes on an answer without a
region; the region is part of the vend cache key, so a region reported
later gets its own entry
- a reported region is asked again after an hour, and at most 10,000
buckets are kept; a failed recheck keeps the reported region, while a
404 or an answer without a region drops it
- while one request rechecks a region past its lifetime, others get the
region reported before; only a bucket without one waits
- the lookup owner checks the caches again before asking the storage,
and any failure of the lookup backs off and completes it for its waiters
- a blank or malformed region header counts as none; a recheck refused
without the header, or with a blank one, keeps the reported region
- The feature flag is checked before the region lookup, so a disabled
feature never contacts the storage
- `CachingCloudCredentialVendor` keys on a fingerprint of the stored
credential, the endpoint and region, and, for `s3_compatible` only,
server vs client access
- `FileOperationsImpl` reads and writes Iceberg metadata on
S3-compatible storage
- `DeltaCredentialsMapper` sets `s3.endpoint` and `client.region`; the
Iceberg REST config also sets `s3.path-style-access`, which that
protocol defines

-
`CloudCredentialVendorTest.testS3CompatibleStsFailureReturnsGeneralError`:
a failed `AssumeRole` on S3-compatible STS returns #2176's general error

- An `endpoint-only` vend to a client carries an expiration an hour
ahead, as a `static-key` one does, so clients that fetch again pick up a
changed endpoint; others pick it up on their first table load after it
- A startup warning when
`server.s3-compatible-storage.static-key-vending=static-key`
- A stored secret that cannot be read during a vend, or an STS response
without complete credentials (a key, secret and session token that are
not blank, and an expiration), returns "Failed to vend temporary storage
credentials."; the server logs the reason

Compatibility: AWS vending is unchanged.

Tests: full server suite.

**PR Checklist**

- [x] A description of the changes is added to the description of this
PR.
- [ ] If there is a related issue, make sure it is linked to this PR.
- [x] If you've fixed a bug or added code that should be tested, add
tests!
- [ ] If you've added or modified a feature, documentation in `docs` is
updated

This pull request and its description were written by Isaac.

Signed-off-by: Yi Li <[email protected]>
Co-authored-by: Isaac <[email protected]>
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.

3 participants