From 8828c76f92e29af09043015a41e547a74bef3b8d Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Mon, 26 Aug 2024 15:32:43 +0200 Subject: [PATCH] rest: improve handling of HTTP2 goaway The HTTP client can only retry HTTP2 requests after receiving a GOAWAY response if it can rewind the body. As we use a custom data type, explicitly provide an implementation of `GetBody`. --- changelog/unreleased/pull-5018 | 13 +++++++++++++ internal/backend/rest/rest.go | 6 ++++++ 2 files changed, 19 insertions(+) create mode 100644 changelog/unreleased/pull-5018 diff --git a/changelog/unreleased/pull-5018 b/changelog/unreleased/pull-5018 new file mode 100644 index 000000000..1b7b9f428 --- /dev/null +++ b/changelog/unreleased/pull-5018 @@ -0,0 +1,13 @@ +Bugfix: Improve HTTP2 support for rest backend + +If rest-server tried to gracefully shut down an HTTP2 connection still used by the client, +this could result in the following error. + +``` +http2: Transport: cannot retry err [http2: Transport received Server's graceful shutdown GOAWAY] after Request.Body was written; define Request.GetBody to avoid this error +``` + +This has been fixed. + +https://github.com/restic/restic/pull/5018 +https://forum.restic.net/t/receiving-http2-goaway-messages-with-windows-restic-v0-17-0/8367 diff --git a/internal/backend/rest/rest.go b/internal/backend/rest/rest.go index 1af88ec3f..d0a08175b 100644 --- a/internal/backend/rest/rest.go +++ b/internal/backend/rest/rest.go @@ -143,6 +143,12 @@ func (b *Backend) Save(ctx context.Context, h backend.Handle, rd backend.RewindR if err != nil { return errors.WithStack(err) } + req.GetBody = func() (io.ReadCloser, error) { + if err := rd.Rewind(); err != nil { + return nil, err + } + return io.NopCloser(rd), nil + } req.Header.Set("Content-Type", "application/octet-stream") req.Header.Set("Accept", ContentTypeV2)