From b4b44986b354148a3507fa8a1542b169b3d5dfe4 Mon Sep 17 00:00:00 2001 From: Martin Angers Date: Mon, 15 Jul 2024 15:36:37 -0400 Subject: [PATCH] Increase software installer upload timeout (#20479) --- ...309-increase-software-installer-upload-timeout | 1 + cmd/fleet/serve.go | 15 +++++++++------ .../AddSoftwareModal/AddSoftwareModal.tsx | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 changes/20309-increase-software-installer-upload-timeout diff --git a/changes/20309-increase-software-installer-upload-timeout b/changes/20309-increase-software-installer-upload-timeout new file mode 100644 index 0000000000..242b7738bd --- /dev/null +++ b/changes/20309-increase-software-installer-upload-timeout @@ -0,0 +1 @@ +* Increased the timeout of the upload software installer endpoint to 4 minutes. diff --git a/cmd/fleet/serve.go b/cmd/fleet/serve.go index 733572b17f..27d5c52641 100644 --- a/cmd/fleet/serve.go +++ b/cmd/fleet/serve.go @@ -75,7 +75,7 @@ import ( var allowedURLPrefixRegexp = regexp.MustCompile("^(?:/[a-zA-Z0-9_.~-]+)+$") -const softwareInstallerUploadTimeout = 2 * time.Minute +const softwareInstallerUploadTimeout = 4 * time.Minute type initializer interface { // Initialize is used to populate a datastore with @@ -1073,16 +1073,19 @@ the way that the Fleet server works. // when uploading a software installer, the file might be large so // the read timeout (to read the full request body) must be extended. rc := http.NewResponseController(rw) - // the frontend times out waiting for the upload after 2 minutes, so + // the frontend times out waiting for the upload after 4 minutes, // use that same timeout: // https://www.figma.com/design/oQl2oQUG0iRkUy0YOxc307/%2314921-Deploy-security-agents-to-macOS%2C-Windows%2C-and-Linux-hosts?node-id=773-18032&t=QjEU6tc73tddNSqn-0 if err := rc.SetReadDeadline(time.Now().Add(softwareInstallerUploadTimeout)); err != nil { level.Error(logger).Log("msg", "http middleware failed to override endpoint read timeout", "err", err) } - // the write timeout should be extended as well to give the server time to - // write a response body with the right error, otherwise the connection is - // terminated abruptly. - if err := rc.SetWriteDeadline(time.Now().Add(softwareInstallerUploadTimeout + 30*time.Second)); err != nil { + // the write timeout should be extended to give the server time to + // store the installer to S3 (or the configured storage location) and + // write a response body, otherwise the connection is terminated + // abruptly. Give it twice the read timeout, so that if it takes + // 3m59s to upload an installer, we don't fail because of a lack of + // time to store to S3. + if err := rc.SetWriteDeadline(time.Now().Add(2 * softwareInstallerUploadTimeout)); err != nil { level.Error(logger).Log("msg", "http middleware failed to override endpoint write timeout", "err", err) } req.Body = http.MaxBytesReader(rw, req.Body, service.MaxSoftwareInstallerSize) diff --git a/frontend/pages/SoftwarePage/components/AddSoftwareModal/AddSoftwareModal.tsx b/frontend/pages/SoftwarePage/components/AddSoftwareModal/AddSoftwareModal.tsx index 3f83cac725..b86d33089c 100644 --- a/frontend/pages/SoftwarePage/components/AddSoftwareModal/AddSoftwareModal.tsx +++ b/frontend/pages/SoftwarePage/components/AddSoftwareModal/AddSoftwareModal.tsx @@ -16,8 +16,8 @@ import AddSoftwareForm from "../AddSoftwareForm"; import { IAddSoftwareFormData } from "../AddSoftwareForm/AddSoftwareForm"; import { getErrorMessage } from "./helpers"; -// 2 minutes + 15 seconds to account for extra roundtrip time. -const UPLOAD_TIMEOUT = (2 * 60 + 15) * 1000; +// 8 minutes + 15 seconds to account for extra roundtrip time. +const UPLOAD_TIMEOUT = (8 * 60 + 15) * 1000; const MAX_FILE_SIZE_MB = 500; const MAX_FILE_SIZE_BYTES = MAX_FILE_SIZE_MB * 1024 * 1024;