Skip to content

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

Merged
thisisnic merged 2 commits into
apache:mainfrom
thisisnic:GH-50009-sigpipe
Jun 8, 2026
Merged

GH-50009: [R] FinalizeS3 segfaults for stale connection#50081
thisisnic merged 2 commits into
apache:mainfrom
thisisnic:GH-50009-sigpipe

Conversation

@thisisnic

@thisisnic thisisnic commented Jun 2, 2026

Copy link
Copy Markdown
Member

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

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

⚠️ 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 Outdated
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 jonkeane left a comment

Copy link
Copy Markdown
Member

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
@thisisnic

Copy link
Copy Markdown
Member Author

This is super hard to test as I've tried reproducing it but am having difficulty doing so. I'm a bit unsure about merging this now.

For: the change is reasonably well supported by similar issues folks have had, tests pass on CI

Against: I'm unable to reproduce the original issue and haven't tested the code beyond CI.

I think maybe let's merge?

@thisisnic thisisnic merged commit 68fb464 into apache:main Jun 8, 2026
15 checks passed
@thisisnic thisisnic removed the awaiting merge Awaiting merge label Jun 8, 2026
@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 3 benchmarking runs that have been run so far on merge-commit 68fb464.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 6 possible false positives for unstable benchmarks that are known to sometimes produce them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants