From 3c95f35553e2b95895926eb925a69198b79b7749 Mon Sep 17 00:00:00 2001 From: Ske Date: Sun, 22 Dec 2019 22:56:18 +0100 Subject: [PATCH] Reduce timeouts on webhook invocations --- PluralKit.Bot/Services/WebhookExecutorService.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/PluralKit.Bot/Services/WebhookExecutorService.cs b/PluralKit.Bot/Services/WebhookExecutorService.cs index 39c0b77b..d3d071e8 100644 --- a/PluralKit.Bot/Services/WebhookExecutorService.cs +++ b/PluralKit.Bot/Services/WebhookExecutorService.cs @@ -30,7 +30,7 @@ namespace PluralKit.Bot _metrics = metrics; _webhookCache = webhookCache; _logger = logger.ForContext(); - _client = new HttpClient(); + _client = new HttpClient {Timeout = TimeSpan.FromSeconds(5)}; } public async Task ExecuteWebhook(ITextChannel channel, string name, string avatarUrl, string content, IReadOnlyCollection attachments) @@ -60,7 +60,10 @@ namespace PluralKit.Bot var attachmentChunks = ChunkAttachmentsOrThrow(attachments, 8 * 1024 * 1024); if (attachmentChunks.Count > 0) + { + _logger.Information($"Invoking webhook with {attachments.Count} attachments totalling {attachments.Select(a => a.Size).Sum() / 1024 / 1024} MiB in {attachmentChunks.Count} chunks"); await AddAttachmentsToMultipart(mfd, attachmentChunks.First()); + } HttpResponseMessage response; using (_metrics.Measure.Timer.Time(BotMetrics.WebhookResponseTime)) @@ -138,7 +141,7 @@ namespace PluralKit.Bot { async Task<(IAttachment, Stream)> GetStream(IAttachment attachment) { - var attachmentResponse = await _client.GetAsync(attachment.Url); + var attachmentResponse = await _client.GetAsync(attachment.Url, HttpCompletionOption.ResponseHeadersRead); return (attachment, await attachmentResponse.Content.ReadAsStreamAsync()); }