Skip to content

EXP: GH-50188: [C++] Make S3 CRT ClientBootstrap shutdown non-blocking - #50193

Draft
pitrou wants to merge 1 commit into
apache:mainfrom
pitrou:gh50188-blocking-shutdown
Draft

pitrou wants to merge 1 commit into
apache:mainfrom
pitrou:gh50188-blocking-shutdown

Conversation

@pitrou

@pitrou pitrou commented Jun 16, 2026

Copy link
Copy Markdown
Member

Thanks for opening a pull request!

If this is your first pull request you can find detailed information on how to contribute here:

Please remove this line and the above text before creating your pull request.

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

This PR includes breaking changes to public APIs. (If there are any breaking changes to public APIs, please explain which changes are breaking. If not, you can remove this.)

This PR contains a "Critical Fix". (If the changes fix either (a) a security vulnerability, (b) a bug that caused incorrect or invalid data to be produced, or (c) a bug that causes a crash (even when the API contract is upheld), please provide explanation. If not, you can remove this.)

@github-actions

Copy link
Copy Markdown

Thanks for opening a pull request!

If this is not a minor PR. Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose

Opening GitHub issues ahead of time contributes to the Openness of the Apache Arrow project.

Then could you also rename the pull request title in the following format?

GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}

or

MINOR: [${COMPONENT}] ${SUMMARY}

See also:

@pitrou pitrou added the CI: Extra: C++ Run extra C++ CI label Jun 16, 2026
@pitrou

pitrou commented Jun 16, 2026

Copy link
Copy Markdown
Member Author

@github-actions crossbow submit wheelcp312*

@github-actions

Copy link
Copy Markdown

Revision: 48d2ad9

Submitted crossbow builds: ursacomputing/crossbow @ actions-b78ab357f0

Task Status
wheel-macos-monterey-cp312-cp312-amd64 GitHub Actions
wheel-macos-monterey-cp312-cp312-arm64 GitHub Actions
wheel-manylinux-2-28-cp312-cp312-amd64 GitHub Actions
wheel-manylinux-2-28-cp312-cp312-arm64 GitHub Actions
wheel-musllinux-1-2-cp312-cp312-amd64 GitHub Actions
wheel-musllinux-1-2-cp312-cp312-arm64 GitHub Actions
wheel-windows-cp312-cp312-amd64 GitHub Actions

@pitrou

pitrou commented Jun 17, 2026

Copy link
Copy Markdown
Member Author

@github-actions crossbow submit -g python

@github-actions

Copy link
Copy Markdown

Revision: 48d2ad9

Submitted crossbow builds: ursacomputing/crossbow @ actions-73a6328000

Task Status
example-python-minimal-build-fedora-conda GitHub Actions
example-python-minimal-build-ubuntu-venv GitHub Actions
test-conda-python-3.10 GitHub Actions
test-conda-python-3.10-hdfs-2.9.2 GitHub Actions
test-conda-python-3.10-hdfs-3.2.1 GitHub Actions
test-conda-python-3.10-pandas-1.3.4-numpy-1.21.2 GitHub Actions
test-conda-python-3.11 GitHub Actions
test-conda-python-3.11-dask-latest GitHub Actions
test-conda-python-3.11-dask-upstream_devel GitHub Actions
test-conda-python-3.11-hypothesis GitHub Actions
test-conda-python-3.11-pandas-latest-numpy-latest GitHub Actions
test-conda-python-3.11-spark-master GitHub Actions
test-conda-python-3.12 GitHub Actions
test-conda-python-3.12-cpython-debug GitHub Actions
test-conda-python-3.12-pandas-latest-numpy-1.26 GitHub Actions
test-conda-python-3.12-pandas-latest-numpy-latest GitHub Actions
test-conda-python-3.13 GitHub Actions
test-conda-python-3.13-pandas-nightly-numpy-nightly GitHub Actions
test-conda-python-3.13-pandas-upstream_devel-numpy-nightly GitHub Actions
test-conda-python-3.14 GitHub Actions
test-conda-python-emscripten GitHub Actions
test-debian-13-python-3-amd64 GitHub Actions
test-debian-13-python-3-i386 GitHub Actions
test-fedora-42-python-3 GitHub Actions
test-ubuntu-22.04-python-3 GitHub Actions
test-ubuntu-24.04-python-3 GitHub Actions

@pitrou

pitrou commented Jun 18, 2026 •

Copy link
Copy Markdown
Member Author

@github-actions crossbow submit wheelcp313*

@github-actions

Copy link
Copy Markdown

Revision: 48d2ad9

Submitted crossbow builds: ursacomputing/crossbow @ actions-056618efab

Task Status
wheel-macos-monterey-cp312-cp312-amd64 GitHub Actions
wheel-macos-monterey-cp312-cp312-arm64 GitHub Actions
wheel-manylinux-2-28-cp312-cp312-amd64 GitHub Actions
wheel-manylinux-2-28-cp312-cp312-arm64 GitHub Actions
wheel-musllinux-1-2-cp312-cp312-amd64 GitHub Actions
wheel-musllinux-1-2-cp312-cp312-arm64 GitHub Actions
wheel-windows-cp312-cp312-amd64 GitHub Actions

@github-actions

Copy link
Copy Markdown

Revision: 48d2ad9

Submitted crossbow builds: ursacomputing/crossbow @ actions-c6b0d8e743

Task Status
wheel-macos-monterey-cp313-cp313-amd64 GitHub Actions
wheel-macos-monterey-cp313-cp313-arm64 GitHub Actions
wheel-manylinux-2-28-cp313-cp313-amd64 GitHub Actions
wheel-manylinux-2-28-cp313-cp313-arm64 GitHub Actions
wheel-musllinux-1-2-cp313-cp313-amd64 GitHub Actions
wheel-musllinux-1-2-cp313-cp313-arm64 GitHub Actions
wheel-windows-cp313-cp313-amd64 GitHub Actions

@ROMNEUVILLE

Copy link
Copy Markdown

Hey,

Thanks for the PR. I'm currently having issues with the deadlock. I was wondering if there is a chance that this PR is going to be deployed one day ?

@pitrou

pitrou commented Sep 14, 2026

Copy link
Copy Markdown
Member Author

@ROMNEUVILLE Are you able to test the PR? We don't know whether it's fixing the issue.

raulcd pushed a commit that referenced this pull request Dec 3, 2026
#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: Closes #50188
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants