Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: segfault on arm due to unaligned atomics #31

Merged
merged 1 commit into from Dec 4, 2020

Conversation

bergotorino
Copy link
Contributor

This fixes the following segfault:

runtime/internal/atomic.goStore64(0x2487864, 0x5fc9a110, 0x0)
/home/konrad/opt/go/src/runtime/internal/atomic/atomic_arm.go:144 +0x1c
github.com/DrmagicE/gmqtt.(*client).setDisconnectedAt(0x2487800, 0x184d7eef, 0xbfea8

The atomics must be 64bit aligned on 32bit architectures because
otherwise the attempt to store a value results in segfault.

See: https://golang.org/pkg/sync/atomic/#pkg-note-BUG

client.go Outdated
@@ -94,6 +94,12 @@ type Client interface {

// Client represents a MQTT client and implements the Client interface
type client struct {
// These two int64s must be at th etop to guarantee they are 64bit aligned
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix the typo: 'th etop to'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

This fixes the following segfault:

runtime/internal/atomic.goStore64(0x2487864, 0x5fc9a110, 0x0)
        /home/konrad/opt/go/src/runtime/internal/atomic/atomic_arm.go:144 +0x1c
github.com/DrmagicE/gmqtt.(*client).setDisconnectedAt(0x2487800, 0x184d7eef, 0xbfea8

The atomics must be 64bit aligned on 32bit architectures because
otherwise an attempt to store results in segfault.

See: https://golang.org/pkg/sync/atomic/#pkg-note-BUG
@codecov-io
Copy link

Codecov Report

Merging #31 (cc83930) into master (622fdd7) will decrease coverage by 0.21%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #31      +/-   ##
==========================================
- Coverage   70.33%   70.12%   -0.22%     
==========================================
  Files          26       26              
  Lines        2353     2353              
==========================================
- Hits         1655     1650       -5     
- Misses        540      546       +6     
+ Partials      158      157       -1     
Impacted Files Coverage Δ
client.go 82.68% <ø> (-1.04%) ⬇️
server.go 53.54% <0.00%> (-0.20%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 622fdd7...d7794b5. Read the comment docs.

@DrmagicE DrmagicE merged commit 02437f7 into DrmagicE:master Dec 4, 2020
@DrmagicE
Copy link
Owner

DrmagicE commented Dec 4, 2020

Thanks for your PR.😄 merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants