GH-50009: [R] FinalizeS3 segfaults for stale connection#50081
Open
thisisnic wants to merge 1 commit into
Open
Conversation
|
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent R session crashes/segfaults on S3 shutdown by ensuring the AWS SDK installs a SIGPIPE handler during S3 initialization, addressing stale-connection SIGPIPE behavior reported in GH-50009 (and related SIGPIPE reports like #32026).
Changes:
- Switch R’s
S3FileSystemcreation path fromEnsureS3Initialized()toInitializeS3()withinstall_sigpipe_handler = true. - Tolerate
InitializeS3()returningInvalidwhen S3 is already initialized.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
294
to
+305
| // We need to ensure that S3 is initialized before we start messing with the | ||
| // options | ||
| StopIfNotOk(fs::EnsureS3Initialized()); | ||
| // options. We use InitializeS3() rather than EnsureS3Initialized() so we can | ||
| // enable the SIGPIPE handler - without it, stale connections in the SDK's | ||
| // connection pool can trigger SIGPIPE during Aws::ShutdownAPI(), which causes | ||
| // R's signal handler to longjmp out of the teardown and segfault (GH-50009). | ||
| fs::S3GlobalOptions options = fs::S3GlobalOptions::Defaults(); | ||
| options.install_sigpipe_handler = true; | ||
| auto status = fs::InitializeS3(options); | ||
| // InitializeS3 returns Invalid if already initialized - that's fine | ||
| if (!status.ok() && !fs::IsS3Initialized()) { | ||
| StopIfNotOk(status); | ||
| } |
jonkeane
approved these changes
Jun 2, 2026
Member
jonkeane
left a comment
There was a problem hiding this comment.
Is it possible to write a test that triggers that segfault? It might be too tricky, but it would be lovely to know that we don't accidentally revert this behavior (for example if the options elsewhere change).
Otherwise this looks good
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
User experiences issues with process crashing when reading/writing from S3. Looks like a stale connection and sigpipe stuff. See also #32026
What changes are included in this PR?
Install sigpipe handler upon S3 initialisation so it'll not kill the process.
Are these changes tested?
No - and I'm not sure how I can really test this out.
Are there any user-facing changes?
No