← Back to Pull requests

GH-50188: [C++][Python] Release S3 credentials providers in FinalizeS3 #55881

Open
unknown opened this pull request with 412 lines diff across 5 files
View on GitHub
unknown unknown commented on Dec 01, 2026 12:03 UTC
Author

Rationale for this change

Since Arrow 24, finalize_s3() hangs forever if an S3FileSystem using web identity credentials is still alive, and so does interpreter exit. Web identity credentials means AWS_WEB_IDENTITY_TOKEN_FILE + AWS_ROLE_ARN, e.g. EKS IRSA. The issue has a deterministic repro using a bogus token.

This is a lifetime issue, not a race:
In the bundled AWS SDK 1.11.778, STSAssumeRoleWebIdentityCredentialsProvider became a CrtCredentialsProvider. It's created with GetDefaultClientBootstrap(), so while it is alive it holds a reference to the default ClientBootstrap. In 1.11.587, used by Arrow 23, it used STSCredentialsClient without CRT.
S3ClientFinalizer releases all S3Clients before Aws::ShutdownAPI(), but the credentials provider is also owned by S3Options::credentials_provider and ClientBuilder::credentials_provider_. A live S3FileSystem keeps it alive, so ShutdownAPI() waits forever for the bootstrap reference to go away.

This is also why removing EnableBlockingShutdown() (#50193) is not enough. The wait moves to ~ApiHandle → aws_thread_join_all_managed, as reported in the issue.

What changes are included in this PR?

FinalizableCredentialsProvider: an AWSCredentialsProvider that delegates to the wrapped provider and drops it on finalization. After that it returns empty credentials. That isn't reachable through Arrow, because S3 operations already fail with "S3 finalized" at that point.
S3ClientFinalizer tracks these wrappers (weak refs) and finalizes them after the client holders.
S3Options::ConfigureDefaultCredentials() and ConfigureAssumeRoleWithWebIdentityCredentials() wrap their providers. These are the ones that can be CRT-based.

A provider assigned directly to S3Options::credentials_provider by C++ users is not wrapped. Its lifetime remains the caller's responsibility.

Are these changes tested?

Yes:
A new test_s3_finalize_with_live_web_identity_fs runs in a subprocess with a timeout and needs no network. It covers both an explicit finalize_s3() and plain interpreter exit with a live filesystem. It times out without this change and passes with it.
The existing S3 tests in test_fs.py pass against minio.
Manually on a Linux build of this branch: the bogus-token repro from the issue now exits.
On an EKS pod with real IRSA credentials (x86_64), reading an object and then exiting works. The released 26.0.1 wheel hangs at exit in the same pod.

Are there any user-facing changes?

Processes using web identity credentials no longer hang in finalize_s3() or at exit.

Was AI used for this PR?

In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.

PR code and description written by:

  • Human

  • AI
  • Reviewed before submission by:

  • Human

  • AI

  • Not reviewed
  • AI usage summary:
    An AI coding assistant (Claude) helped trace the root cause through the Arrow and AWS SDK sources, wrote the code change, test and description, and ran the builds and repros.
    I directed the investigation, reproduced the issue, and validated the fix on EKS with IRSA.

    GitHub Issue: Closes #50188

    Diff: 412 lines (+309 / -103) across 5 files Reviewer: raulcd Review duration: 2400m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.45) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 412 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.360
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #55881"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 44.9% (MEDIUM) · Higher = larger blast radius
    44.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 23.9% · Safe to merge
    23.9%
    Repository