Closed cirth9 closed 3 months ago
请简单描述bug的场景 在测试连接远端apollo客户端的时候出现的panic。 操作系统Windows 11 专业版 64位,基于x64处理器,理论不该出现这种panic的。
如何重现 出现panic的代码
package main import ( "fmt" "github.com/apolloconfig/agollo/v4" "github.com/apolloconfig/agollo/v4/env/config" ) func main() { c := &config.AppConfig{ AppID: "permission-manager", Cluster: "dev01", NamespaceName: "tec-do2.0.permission_manager", IP: "http://172.24.2.121:8080", IsBackupConfig: true, Secret: "39bfbb6f1d69424ab02ba6f5da265386", } client, _ := agollo.StartWithConfig(func() (*config.AppConfig, error) { return c, nil }) fmt.Println("初始化Apollo配置成功") //Use your apollo key to test cache := client.GetConfigCache(c.NamespaceName) value, _ := cache.Get("permission_manager_config") fmt.Println(value) }
报错
panic: unaligned 64-bit atomic operation goroutine 1 [running]: runtime/internal/atomic.panicUnaligned() D:/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.windows-386/src/runtime/internal/atomic/unaligned.go:8 +0x2b runtime/internal/atomic.Xadd64(0x188add4, 0x1) D:/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.windows-386/src/runtime/internal/atomic/atomic_386.s:125 +0x11 github.com/apolloconfig/agollo/v4/agcache/memory.(*DefaultCache).Set(0x188adc0, {0x189c4e0, 0x19}, {0x53ce00, 0x188c3c0}, 0x78) D:/go/pkg/mod/github.com/apolloconfig/agollo/v4@v4.4.0/agcache/memory/memory.go:37 +0x76 github.com/apolloconfig/agollo/v4/storage.(*Cache).UpdateApolloConfigCache(0x18cc1b0, 0x188b0a0, 0x78, {0x59325b, 0x1c}) D:/go/pkg/mod/github.com/apolloconfig/agollo/v4@v4.4.0/storage/repository.go:539 +0x4d1 github.com/apolloconfig/agollo/v4/storage.(*Cache).UpdateApolloConfig(0x18cc1b0, 0x18c56c0, 0x18aff58) D:/go/pkg/mod/github.com/apolloconfig/agollo/v4@v4.4.0/storage/repository.go:468 +0xa0 github.com/apolloconfig/agollo/v4.StartWithConfig(0x18affa0) D:/go/pkg/mod/github.com/apolloconfig/agollo/v4@v4.4.0/client.go:134 +0x23c main.main() D:/goland/TestApolloClient/main.go:19 +0xaa
最终溯源到这里,大概是这个地方出现了问题,不是很能理解为何panic了
package memory import ( "errors" "sync" "sync/atomic" "github.com/apolloconfig/agollo/v4/agcache" ) //DefaultCache 默认缓存 type DefaultCache struct { defaultCache sync.Map count int64 } //Set 获取缓存 func (d *DefaultCache) Set(key string, value interface{}, expireSeconds int) (err error) { d.defaultCache.Store(key, value) atomic.AddInt64(&d.count, int64(1)) return nil }
没事了,可以关闭了,排查发现是公司golang环境变量默认设置的386架构导致的。
妈的 好脑残
妈的 好脑残 我也觉得😭主要以前都没遇到过这个64位对齐的panic,GOARCH默认就是64位的,那个时候刚入职公司,没想到公司发的电脑go环境GOARCH默认32位的。 这个库估计现在只适用于64位系统吧,还是希望后面能加一下。
请简单描述bug的场景 在测试连接远端apollo客户端的时候出现的panic。 操作系统Windows 11 专业版 64位,基于x64处理器,理论不该出现这种panic的。
如何重现 出现panic的代码
报错
最终溯源到这里,大概是这个地方出现了问题,不是很能理解为何panic了