Skip to content

Commit 02437f7

Browse files
authored
Merge pull request #31 from bergotorino/fix/segfault-on-arm
fix: segfault on arm due to unaligned atomics
2 parents 622fdd7 + d7794b5 commit 02437f7

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

client.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ type Client interface {
9494

9595
// Client represents a MQTT client and implements the Client interface
9696
type client struct {
97+
// These two int64s must be at the top to guarantee they are 64bit aligned
98+
// on 32bit architectures. If not then an attempt to store results in
99+
// segfault. See: https://golang.org/pkg/sync/atomic/#pkg-note-BUG
100+
connectedAt int64
101+
disconnectedAt int64
102+
97103
server *server
98104
wg sync.WaitGroup
99105
rwc net.Conn //raw tcp connection
@@ -115,9 +121,6 @@ type client struct {
115121
keys map[string]interface{}
116122
ready chan struct{} //close after session prepared
117123

118-
connectedAt int64
119-
disconnectedAt int64
120-
121124
statsManager SessionStatsManager
122125
}
123126

0 commit comments

Comments
 (0)