Go SDK panics with: unaligned 64-bit atomic operation on x86_64 Ubuntu Server

I compiled a 386 binary for Ubuntu using env GOOS=linux GOARCH=386 go build main.go and uploaded it to my server, however when I run my app, I’m getting the following error on Couchbase Connex:

panic: unaligned 64-bit atomic operation

goroutine 10 [running]:
runtime/internal/atomic.panicUnaligned()
	/usr/local/go/src/runtime/internal/atomic/unaligned.go:8 +0x2d
runtime/internal/atomic.Store64(0x94b72f4, 0x0)
	/usr/local/go/src/runtime/internal/atomic/atomic_386.s:237 +0x10
github.com/couchbase/gocbcore/v10.(*lazyCircuitBreaker).Reset(0x94b72c0)
	/Users/liwu/go/pkg/mod/github.com/couchbase/gocbcore/v10@v10.1.4/circuitbreaker.go:135 +0xe6
github.com/couchbase/gocbcore/v10.newLazyCircuitBreaker({0x1, 0x14, 0x4049000000000000, 0x12a05f200, 0xdf8475800, 0x83c1d90, 0x12a05f200}, 0x9493560)
	/Users/liwu/go/pkg/mod/github.com/couchbase/gocbcore/v10@v10.1.4/circuitbreaker.go:127 +0x18f
github.com/couchbase/gocbcore/v10.newMemdClient({{0x94ab390, 0x10}, 0x0, 0x20, 0x3fea8f5c28f5c28f, 0x0}, {0x8424dcc, 0x9495840}, {0x1, 0x0, ...}, ...)
	/Users/liwu/go/pkg/mod/github.com/couchbase/gocbcore/v10@v10.1.4/memdclient.go:110 +0x2bd
github.com/couchbase/gocbcore/v10.(*memdClientDialerComponent).dialMemdClient(0x94fa580, 0x9480e40, {{0x94ca438, 0x13}, 0x1}, {0xc0b0bba86ed34f8d, 0x413554ccf, 0x85f5580}, 0x940c250, 0x0)
	/Users/liwu/go/pkg/mod/github.com/couchbase/gocbcore/v10@v10.1.4/memdclientdialer_component.go:192 +0x3ff
github.com/couchbase/gocbcore/v10.(*memdClientDialerComponent).SlowDialMemdClient(0x94fa580, 0x9480e40, {{0x94ca438, 0x13}, 0x1}, 0x0, 0x9484e70, {0x94b47f8, 0x3, 0x3}, ...)
	/Users/liwu/go/pkg/mod/github.com/couchbase/gocbcore/v10@v10.1.4/memdclientdialer_component.go:118 +0x2b5
github.com/couchbase/gocbcore/v10.(*kvMux).newKVMuxState.func1(0x9480e40)
	/Users/liwu/go/pkg/mod/github.com/couchbase/gocbcore/v10@v10.1.4/kvmux.go:692 +0xf2
github.com/couchbase/gocbcore/v10.(*memdPipelineClient).Run.func1(0x9488a20, 0x955e400, 0x9452d40)
	/Users/liwu/go/pkg/mod/github.com/couchbase/gocbcore/v10@v10.1.4/memdpipelineclient.go:219 +0x2a
created by github.com/couchbase/gocbcore/v10.(*memdPipelineClient).Run
	/Users/liwu/go/pkg/mod/github.com/couchbase/gocbcore/v10@v10.1.4/memdpipelineclient.go:218 +0x263

The problem manifests because of the 32-bit (GOARCH=386) build; Is there a reason for needing a 32-bit build ?
You can demo the issue in Go simply with:

package main;
import "sync/atomic"
type Eg struct {
        u32 uint32
        u64 uint64
}
func main() {
        var eg Eg
        atomic.StoreUint64(&eg.u64, uint64(0))
}

Which when built with:

GOOS=linux GOARCH=386 go build eg.go

Will panic similarly - since go structure members aren’t 64-bit aligned in a 32-bit build.
(If built with GOARCH=amd64 of course it works.)

HTH.

1 Like

Will be addressed via: https://issues.couchbase.com/browse/GOCBC-1338