Skip to content

Commit

Permalink
Fixed 64-bit alignment panic in chunkedContentCoder on 32-bit platfor…
Browse files Browse the repository at this point in the history
…ms. (#148)

Following the fix in #147, a 'panic: unaligned 64-bit atomic operation' is
still occurring on some platforms.

As noted in #147, this commit implements the alternative fix by placing the
bytesWritten field at the top of the struct. Per the Golang sync/atomic
documentation, on ARM, 386 and 32-bit MIPS systems, this is the reliable
way to prevent these issues.

Signed-off-by: Callum Jones <cj@icj.me>
  • Loading branch information
cj123 authored Feb 21, 2023
1 parent e34dce0 commit 67addef
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion contentcoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ var (
)

type chunkedContentCoder struct {
bytesWritten uint64 // atomic access to this variable, moved to top to correct alignment issues on ARM, 386 and 32-bit MIPS.

final []byte
chunkSize uint64
currChunk uint64
Expand All @@ -45,7 +47,6 @@ type chunkedContentCoder struct {
compressed []byte // temp buf for snappy compression

w io.Writer
bytesWritten uint64 // atomic access to this variable
progressiveWrite bool

chunkMeta []MetaData
Expand Down

0 comments on commit 67addef

Please sign in to comment.