Comments (5)
Interesting. If I had to guess it's because ARMv7 is a 32bit chip, whereas the atomic counters in the broker are set to use 64bit ints. Is this something you are relying on? I can have a think about how this issue can be fixed, and I welcome suggestions from anyone else!
from server.
Thanks for the quick response! Shouldn't 32-bit be enough for the broker counters?
Could using int
where possible and wrapping the sync/atomic
with 32/64-bit check for calling say AddUint64 or AddUint32 be a partial solution?
package atomthic
import (
"sync/atomic"
)
const uintSize = 32 << (^uint(0) >> 32 & 1)
func AddInt(addr *int, delta int) int {
var c int
if uintSize == 64 {
var a int64 = int64(*addr)
var b = atomic.AddInt64(&a, int64(delta))
c = int(b)
} else {
var a int32 = int32(*addr)
var b = atomic.AddInt32(&a, int32(delta))
c = int(b)
}
return c
}
func AddUint(addr *uint, delta uint) uint {
var c uint
if uintSize == 64 {
var a uint64 = uint64(*addr)
var b = atomic.AddUint64(&a, uint64(delta))
c = uint(b)
} else {
var a uint32 = uint32(*addr)
var b = atomic.AddUint32(&a, uint32(delta))
c = uint(b)
}
return c
}
func LoadInt(addr *int) int {
var c int
if uintSize == 64 {
var a int64 = int64(*addr)
c = int(atomic.LoadInt64(&a))
} else {
var a int32 = int32(*addr)
c = int(atomic.LoadInt32(&a))
}
return c
}
func LoadUint(addr *uint) uint {
var c uint
if uintSize == 64 {
var a uint64 = uint64(*addr)
c = uint(atomic.LoadUint64(&a))
} else {
var a uint32 = uint32(*addr)
c = uint(atomic.LoadUint32(&a))
}
return c
}
func StoreInt(addr *int, val int) {
if uintSize == 64 {
var a int64 = int64(*addr)
var b = int64(val)
atomic.StoreInt64(&a, b)
} else {
var a int32 = int32(*addr)
var b = int32(val)
atomic.StoreInt32(&a, b)
}
}
func StoreUint(addr *uint, val uint) {
if uintSize == 64 {
var a uint64 = uint64(*addr)
var b = uint64(val)
atomic.StoreUint64(&a, b)
} else {
var a uint32 = uint32(*addr)
var b = uint32(val)
atomic.StoreUint32(&a, b)
}
}
from server.
I'm seeing something similar on what I'm pretty sure is the same hardware. I'm my case, the panic is from an unaligned operation:
/tmp/mqtt $ go run examples/tcp/main.go
Mochi MQTT Server initializing... TCP
Started!
panic: unaligned 64-bit atomic operation
goroutine 37 [running]:
runtime/internal/atomic.panicUnaligned()
/usr/local/go/src/runtime/internal/atomic/unaligned.go:8 +0x24
runtime/internal/atomic.Load64(0x8be03c)
/usr/local/go/src/runtime/internal/atomic/atomic_arm.s:286 +0x14
github.com/mochi-co/mqtt/server/listeners.(*TCP).Serve(0x8be000, 0x8a6028)
/tmp/mqtt/server/listeners/tcp.go:89 +0x28
github.com/mochi-co/mqtt/server/listeners.(*Listeners).Serve.func1(0x8bc000, {0x295934, 0x8be00
0}, 0x8a6028)
/tmp/mqtt/server/listeners/listeners.go:94 +0x70
created by github.com/mochi-co/mqtt/server/listeners.(*Listeners).Serve
/tmp/mqtt/server/listeners/listeners.go:91 +0x9c
exit status 2
I'm using v1.0.4 with Go 1.17.6.
I'm pretty sure none of the functions in ogelami's reply are atomic anymore, and some of them end up storing into the wrong place. I think you can use unsafe.Sizeof
instead of bit-twiddling, but I wonder whether just using uintptr
might be a simpler fix. There are functions in atomic
for that type already. I tried making that change and it seemed to work. I can submit a PR if you like.
from server.
I wonder whether just using uintptr might be a simpler fix. There are functions in atomic for that type already. I tried making that change and it seemed to work. I can submit a PR if you like.
@rkennedy I have been thinking along similar lines and would love to see what you've come up with.
I think there might be some trivial improvements to be had by re-aligning the struct declarations across the board, so I am continuing to look into that.
from server.
After extensive testing, I have released @rkennedy 's fix for this as v1.1.0! Thank you @ogelami and @rkennedy for your hard work and making the project better!
from server.
Related Issues (20)
- After enabled badger, the vlog file up to 700M one day and 4GB one week HOT 9
- Race condition when running the redis example HOT 4
- 遍历Clients时如何判断当前Client是否为Disconected状态 HOT 3
- 作者您好,请帮忙关注一下这个问题 HOT 3
- Hi, what is the simplest way to make messages can be restored when server cut off? HOT 5
- [badgerdb] vlog growing unbounded - consider adding GC and exposing options HOT 6
- The badge still getting vlog file keep growing infirnity HOT 7
- How to send topics posted by specific users only to specific subscribed users? HOT 11
- Does peddle perssistant released? HOT 5
- MQTTX cannot use Topic Alias. MQTT5.0 主题别名发送卡住,无法发布主题别名的消息 HOT 2
- How to use the new pessistent hook? HOT 1
- Reload auth fIle on the run HOT 2
- InlineClient模式下服务端订阅问题,inline subscribers do not receive messages HOT 5
- Merge 2 version of storm HOT 4
- Add Support for Disconnect With Will Message Reason Code
- Logging Level is not Configurable Via File Configuration
- Persistence storage did not work with SetCleanSession(false) HOT 3
- Don't allow inheriting session unless username matches HOT 5
- MessageExpiry Hook HOT 1
- OnConnectAuthenticate cannot specify an error code (like Client Identifier not valid)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from server.