【发布时间】:2017-06-16 10:20:38
【问题描述】:
拥有接收请求、生成数据并将其以文件形式保存到 AWS S3 的服务。 如果服务收到许多请求,则可以尝试并行保存多达 20 个文件(2 个服务器 x 10 个工作人员)。 请求生成并保存到 S3 的数据可以从几 KB 到大约 400MB
问题是有时(似乎是当服务很忙/要保存大文件时)S3 失败,但以下异常: 我们讨论了 2 个解决方案:
1) 如果保存失败,则重试 S3.UploadAsync()。 不确定是否会有所作为。假设 S3 已经在内部重试,所以可能没有必要重试。如果问题是文件太大/保存时间过长,这将无法解决问题,可能会使问题变得更糟。
2) 将 TransferUtilityConfig.DefaultTimeout 增加到 10 分钟(默认为 5 分钟)。 如果问题是保存时间超过 5 分钟,这将解决问题,但 S3 抛出的异常并不表示是超时异常,所以也许这可以解决任何问题。
3) 这是 AWS 基础设施中的间歇性问题吗?重试可以帮忙吗?
发生此异常时,是否有人有经验/解决方案?还有其他想法吗?
更新: 如果使用 NET 4.5,则 TransferUtilityConfig() 不包含 DefaultTimeout。该功能已移至 AmazonS3Config。这提供了更多参数来控制上传:Timeout、ReadWriteTimeout、MaxErrorRetry AmazonS3Config Class 设置在这里解释 AWS Retries and Timeouts
这是服务用来保存的代码:
using (var amazonS3Client = new AmazonS3Client(RegionEndpoint.GetBySystemName(_iAwsS3Settings.RegionEndpoint)))
using (var fileTransferUtility = new TransferUtility(amazonS3Client))
using (var memoryStream = new MemoryStream(data))
{
var fileTransferUtilityRequest = new TransferUtilityUploadRequest
{
BucketName = _iAwsS3Settings.BucketName,
InputStream = memoryStream,
StorageClass = S3StorageClass.ReducedRedundancy,
PartSize = 6291456, // 6 MB.
Key = fileLocation,
CannedACL = S3CannedACL.BucketOwnerFullControl
};
await fileTransferUtility.UploadAsync(fileTransferUtilityRequest, ct);
}
这是 S3 保存失败时给出的异常:
System.AggregateException:发生一个或多个错误。 ---> Amazon.Runtime.AmazonServiceException:带有状态的 WebException SecureChannelFailure 被抛出。 ---> System.Net.WebException: 请求被中止:无法创建 SSL/TLS 安全通道。在 System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult、TransportContext& 上下文)在 System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult) 在 System.Threading.Tasks.TaskFactory
1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization) --- 上一个堆栈跟踪的结束 抛出异常的位置---在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)在 Amazon.Runtime.Internal.HttpHandler1.<InvokeAsync>d__91.MoveNext() --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 Amazon.Runtime.Internal.HttpHandler1.<InvokeAsync>d__91.MoveNext() --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)在 Amazon.Runtime.Internal.RedirectHandler.d__11.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Amazon.Runtime.Internal.Unmarshaller.<InvokeAsync>d__31.MoveNext() --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)在 Amazon.S3.Internal.AmazonS3ResponseHandler.d__11.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Amazon.Runtime.Internal.ErrorHandler.<InvokeAsync>d__51.MoveNext() --- 内部异常堆栈跟踪结束 --- 在 Amazon.Runtime.Internal.WebExceptionHandler.HandleException(IExecutionContext executionContext,WebException 异常)在 Amazon.Runtime.Internal.ErrorHandler.ProcessException(IExecutionContext executionContext,异常异常)在 Amazon.Runtime.Internal.ErrorHandler.d__51.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__91.MoveNext() --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)在 Amazon.Runtime.Internal.CredentialsRetriever.d__71.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__101.MoveNext() --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 Amazon.Runtime.Internal.RetryHandler.d__10`1.MoveNext()
【问题讨论】:
标签: c# amazon-web-services amazon-s3