diff --git a/cpp/src/arrow/filesystem/s3fs.cc b/cpp/src/arrow/filesystem/s3fs.cc index ac373a69e7cd6..eaf4b789739aa 100644 --- a/cpp/src/arrow/filesystem/s3fs.cc +++ b/cpp/src/arrow/filesystem/s3fs.cc @@ -3483,7 +3483,14 @@ Status EnsureS3Initialized() { } Status FinalizeS3() { - GetAwsInstance()->Finalize(); + auto instance = GetAwsInstance(); + // The AWS instance might already be destroyed in case FinalizeS3 + // is called from an atexit handler (which is a bad idea anyway as the + // AWS SDK is not safe anymore to shutdown by this time). See GH-44071. + if (instance == nullptr) { + return Status::Invalid("FinalizeS3 called too late"); + } + instance->Finalize(); return Status::OK(); }