From 7f7d9b029dba8489b460f2bbd9a23ce4881e6a71 Mon Sep 17 00:00:00 2001 From: Marius Kleidl Date: Thu, 14 Dec 2023 08:42:25 +0100 Subject: [PATCH] handler: Fix panic on GOARCH=386 Fixes https://github.com/tus/tusd/issues/1047 --- pkg/handler/body_reader.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/handler/body_reader.go b/pkg/handler/body_reader.go index 6ca7a0f44..8f8d2e3f7 100644 --- a/pkg/handler/body_reader.go +++ b/pkg/handler/body_reader.go @@ -19,10 +19,16 @@ import ( // the error but this can instead be done in the handler. // In addition, the bodyReader keeps track of how many bytes were read. type bodyReader struct { + // bytesCounter is the first field to ensure that its properly aligned, + // otherwise we run into alignment issues on some 32-bit builds. + // See https://github.com/tus/tusd/issues/1047 + // See https://pkg.go.dev/sync/atomic#pkg-note-BUG + // TODO: In the future we should move all of these values to the safe + // atomic.Uint64 type, which takes care of alignment automatically. + bytesCounter int64 ctx *httpContext reader io.ReadCloser err error - bytesCounter int64 onReadDone func() }