Skip to content

Use atomic.Uint64 for MemoryBackend upload counting on i386#60

Merged
FiloSottile merged 2 commits intomainfrom
copilot/fix-unaligned-atomic-operation
Mar 18, 2026
Merged

Use atomic.Uint64 for MemoryBackend upload counting on i386#60
FiloSottile merged 2 commits intomainfrom
copilot/fix-unaligned-atomic-operation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 18, 2026

The internal/ctlog tests use a MemoryBackend upload counter that is updated atomically during sequencing. On i386, the previous raw uint64 field could be misaligned inside the struct, triggering panic: unaligned 64-bit atomic operation.

  • Switch the counter to a typed atomic

    • Replace MemoryBackend.uploads uint64 with atomic.Uint64
    • Use the typed API for increments in Upload
  • Update test reads to use atomic loads

    • Adjust TestSequenceUploadCount to read the counter with .Load() before computing deltas
    • Preserve existing test behavior while avoiding direct access to the atomic value
  • Net effect

    • Keeps the change scoped to the test backend
    • Makes the upload counter safe on 32-bit architectures without changing sequencing logic
type MemoryBackend struct {
    // ...
    uploads atomic.Uint64
}

func (b *MemoryBackend) Upload(...) error {
    b.uploads.Add(1)
    // ...
}

new := tl.Config.Backend.(*MemoryBackend).uploads.Load()
Original prompt

This section details on the original issue you should resolve

<issue_title>i386: FAIL: TestSequenceOneLeaf (0.03s) panic: unaligned 64-bit atomic operation [recovered, repanicked]</issue_title>
<issue_description>Hi! I'm packaging this for Debian, and builds on 32-bit architecture i386 fails like this:

--- FAIL: TestSequenceOneLeaf (0.03s)
panic: unaligned 64-bit atomic operation [recovered, repanicked]
goroutine 21 [running]:
testing.tRunner.func1.2({0x8aa5940, 0x8c35da0})
	/usr/lib/go-1.26/src/testing/testing.go:1974 +0x29b
testing.tRunner.func1()
	/usr/lib/go-1.26/src/testing/testing.go:1977 +0x409
panic({0x8aa5940, 0x8c35da0})
	/usr/lib/go-1.26/src/runtime/panic.go:860 +0x10b
internal/runtime/atomic.panicUnaligned()
	/usr/lib/go-1.26/src/internal/runtime/atomic/unaligned.go:8 +0x2d
internal/runtime/atomic.Xadd64(0xd0400dc, 0x1)
	/usr/lib/go-1.26/src/internal/runtime/atomic/atomic_386.s:127 +0x11
filippo.io/sunlight/internal/ctlog_test.(*MemoryBackend).Upload(0xd0400c0, {0x8c3df84, 0xd13b740}, {0x8be22a9, 0xa}, {0xd0dc000, 0x24f, 0x280}, 0x93b32e8)
	/build/package/package/_build/src/filippo.io/sunlight/internal/ctlog/testlog_test.go:455 +0x58
filippo.io/sunlight/internal/ctlog.CreateLog({0x8c3df84, 0xd13b740}, 0xd0aa0c0)
	/build/package/package/_build/src/filippo.io/sunlight/internal/ctlog/ctlog.go:151 +0x799
filippo.io/sunlight/internal/ctlog_test.NewEmptyTestLog({0x8c41efc, 0xd108b48})
	/build/package/package/_build/src/filippo.io/sunlight/internal/ctlog/testlog_test.go:68 +0x814
filippo.io/sunlight/internal/ctlog_test.TestSequenceOneLeaf(0xd108b48)
	/build/package/package/_build/src/filippo.io/sunlight/internal/ctlog/ctlog_test.go:38 +0x2f
testing.tRunner(0xd108b48, 0x8c30e24)
	/usr/lib/go-1.26/src/testing/testing.go:2036 +0x114
created by testing.(*T).Run in goroutine 1
	/usr/lib/go-1.26/src/testing/testing.go:2101 +0x511
FAIL	filippo.io/sunlight/internal/ctlog	0.047s

https://salsa.debian.org/jas/golang-filippo-sunlight/-/jobs/9252969

Thanks,
Simon</issue_description>

<agent_instructions>Fix this by replacing the uint64 uploads field with a sync/atomic.Uint64.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Co-authored-by: FiloSottile <1225294+FiloSottile@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix panic during TestSequenceOneLeaf on i386 Use atomic.Uint64 for MemoryBackend upload counting on i386 Mar 18, 2026
Copilot AI requested a review from FiloSottile March 18, 2026 18:30
@FiloSottile FiloSottile marked this pull request as ready for review March 18, 2026 18:39
@FiloSottile FiloSottile merged commit 893a6c2 into main Mar 18, 2026
10 of 12 checks passed
@FiloSottile FiloSottile deleted the copilot/fix-unaligned-atomic-operation branch March 20, 2026 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

i386: FAIL: TestSequenceOneLeaf (0.03s) panic: unaligned 64-bit atomic operation [recovered, repanicked]

2 participants