Skip to content

GH-50009: [R] FinalizeS3 segfaults for stale connection#50081

Open
thisisnic wants to merge 1 commit into
apache:mainfrom
thisisnic:GH-50009-sigpipe
Open

GH-50009: [R] FinalizeS3 segfaults for stale connection#50081
thisisnic wants to merge 1 commit into
apache:mainfrom
thisisnic:GH-50009-sigpipe

Conversation

@thisisnic
Copy link
Copy Markdown
Member

@thisisnic thisisnic commented Jun 2, 2026

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

Copilot AI review requested due to automatic review settings June 2, 2026 10:33
@thisisnic thisisnic requested a review from jonkeane as a code owner June 2, 2026 10:33
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

⚠️ GitHub issue #50009 has been automatically assigned in GitHub to PR creator.

@github-actions github-actions Bot added Component: R awaiting committer review Awaiting committer review labels Jun 2, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 S3FileSystem creation path from EnsureS3Initialized() to InitializeS3() with install_sigpipe_handler = true.
  • Tolerate InitializeS3() returning Invalid when S3 is already initialized.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread r/src/filesystem.cpp
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);
}
Copy link
Copy Markdown
Member

@jonkeane jonkeane left a comment

Choose a reason for hiding this comment

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

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

@github-actions github-actions Bot added awaiting merge Awaiting merge and removed awaiting committer review Awaiting committer review labels Jun 2, 2026
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