jpatra72 opened a new pull request, #55881:
URL: https://github.com/apache/arrow/pull/55881

   ### 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 `S3Client`s 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](https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code),
 please disclose below whether and how AI was used in this PR.
   
   **PR code and description written by:**
   
   - [ ] Human
   - [x] AI
   
   **Reviewed before submission by:**
   
   - [x] Human
   - [x] 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: #50188
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to