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)
- Potential performance decrease with bufio on write HOT 17
- 测试paho.mqtt.testing的时候发现这个用例报错呢,Subscribe failure test HOT 4
- mqtt5 client 无法获取clientID HOT 2
- Very nice work, will this repo keep maintained? HOT 1
- Can not close example with ctrl + c HOT 4
- How to call server.Publish() inside a hook? 如何在hooks的函数里面直接使用server.Publish()? HOT 2
- An Issue with Client Connection in Dart Language 一个非常奇怪的bug HOT 25
- 怎么在Hook里面访问Publish? HOT 2
- how to override payload when do message inceptor?
- Got nil exception when inceptor publish HOT 4
- Can not get onPublish called after set Inline Client HOT 10
- invalid client status which loaded from storage. HOT 6
- consume very slow when Inflights to many HOT 4
- Packet encoding optimization HOT 1
- Data race in buffer with v2.4.3 HOT 4
- Client unsubscribe topic have problem HOT 1
- Version is "2.4.1" while the package version is v2.4.3 HOT 2
- message does not save at session when client is disconnect HOT 21
- OnACLCheck BUG HOT 11
- How to enable storage simplify HOT 16
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.