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

invalid memory address or nil pointer dereference #31

Closed
erebusdark opened this issue Sep 19, 2019 · 16 comments
Closed

invalid memory address or nil pointer dereference #31

erebusdark opened this issue Sep 19, 2019 · 16 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@erebusdark
Copy link

erebusdark commented Sep 19, 2019

I am using the github.com/kpango/glg package that in turn is using this package. When I run my code on a x86_64 machine it works, no problems what so ever, but when I compile it and try to run it on a arm processor (Raspberry Pi 3) it panics and crashes with the following error

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x4 pc=0x114fc]
goroutine 17 [running]:
sync/atomic.storeUint64(0x1101e034, 0x4c4b40, 0x0)
/usr/lib/go-1.10/src/sync/atomic/64bit_arm.go:20 +0x3c
github.com/kpango/fastime.(*Fastime).StartTimerD.func1(0x1101e000, 0x4c4b40, 0x0, 0x386220, 0x110001e0)
/home/user/go/src/github.com/kpango/fastime/fastime.go:181 +0x64
created by github.com/kpango/fastime.(*Fastime).StartTimerD
/home/user/go/src/github.com/kpango/fastime/fastime.go:179 +0xb8

@issue-label-bot
Copy link

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.96. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@issue-label-bot issue-label-bot bot added the bug Something isn't working label Sep 19, 2019
@kpango
Copy link
Owner

kpango commented Sep 27, 2019

@erebusdark Hi. I'm so sorry I didn't notice for a long time

which Go version are u using? 1.10?

@kpango
Copy link
Owner

kpango commented Sep 27, 2019

@erebusdark can u test on Go 1.13?

@erebusdark
Copy link
Author

I will check with Go 1.13 during next week when I am back so I can test it. Will update this once I have tested it.

@erebusdark
Copy link
Author

I was using 1.10 but get the same error with 1.13.1

@kpango
Copy link
Owner

kpango commented Oct 2, 2019

can you show me the error log with Go 1.13.1?

@erebusdark
Copy link
Author

[signal SIGSEGV: segmentation violation code=0x1 addr=0x4 pc=0x12488]

goroutine 18 [running]:
github.com/kpango/fastime.(*Fastime).StartTimerD.func1(0x1c84140, 0x4c4b40, 0x0, 0x2bf3e8, 0x1c6a9a0)
        /home/erebus/go/src/github.com/kpango/fastime/fastime.go:181 +0x60
created by github.com/kpango/fastime.(*Fastime).StartTimerD
        /home/erebus/go/src/github.com/kpango/fastime/fastime.go:179 +0xb4

The file is very simple and it looks like this:

package main

import (
	"github.com/kpango/glg"
)

func main() {
	infolog := glg.FileWriter("./info.log", 0666)
	errorlog := glg.FileWriter("./error.log", 0666)

	defer infolog.Close()
	defer errorlog.Close()

	glg.Get().
		SetMode(glg.BOTH).
		AddLevelWriter(glg.ERR, errorlog).
		AddLevelWriter(glg.INFO, infolog)
}

@kpango
Copy link
Owner

kpango commented Oct 2, 2019

could you please give me raw. stdout result?
below is too short

[signal SIGSEGV: segmentation violation code=0x1 addr=0x4 pc=0x12488]

goroutine 18 [running]:
github.com/kpango/fastime.(*Fastime).StartTimerD.func1(0x1c84140, 0x4c4b40, 0x0, 0x2bf3e8, 0x1c6a9a0)
        /home/erebus/go/src/github.com/kpango/fastime/fastime.go:181 +0x60
created by github.com/kpango/fastime.(*Fastime).StartTimerD
        /home/erebus/go/src/github.com/kpango/fastime/fastime.go:179 +0xb4

@erebusdark
Copy link
Author

I am not sure how to get the raw stdout.

@kpango
Copy link
Owner

kpango commented Oct 2, 2019

please paste raw result below

echo "$(go version)\n$(go run main.go)" >> result.txt

the code of fastime.go:181, I just use atomic.StoreUint64() there is no problem about that we can find stdlibs problem by assembly error like you paste

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x4 pc=0x114fc]
goroutine 17 [running]:
sync/atomic.storeUint64(0x1101e034, 0x4c4b40, 0x0)
/usr/lib/go-1.10/src/sync/atomic/64bit_arm.go:20 +0x3c
github.com/kpango/fastime.(*Fastime).StartTimerD.func1(0x1101e000, 0x4c4b40, 0x0, 0x386220, 0x110001e0)
/home/user/go/src/github.com/kpango/fastime/fastime.go:181 +0x64
created by github.com/kpango/fastime.(*Fastime).StartTimerD
/home/user/go/src/github.com/kpango/fastime/fastime.go:179 +0xb8

@erebusdark
Copy link
Author

Ah, that is a problem sense I don't have go on the raspberry pi.
I compile it with "env GOOS=linux GOARCH=arm GOARM=7 go build" and then move the executable to the pi.

I did just find this however:

On ARM, x86-32, and 32-bit MIPS, it is the caller's responsibility to arrange for 64-bit alignment of 64-bit words accessed atomically. The first word in a variable or in an allocated struct, array, or slice can be relied upon to be 64-bit aligned.

from https://golang.org/pkg/sync/atomic/
so I am guessing that has something to do with it.

@kpango
Copy link
Owner

kpango commented Oct 2, 2019

Oh that's make sense.
So, I should pre-allocate f.dur memory not initial value.
Please use master version of fastime I implemented pre-allocate things.
c67c73e

@erebusdark
Copy link
Author

erebusdark commented Oct 2, 2019

This is very odd, I tried it with the update, it ran fine, then I tried running it again and now it crashed again. With that fix it seems to not happen sometimes but a lot of times it seems to still have the issue..

@erebusdark erebusdark reopened this Oct 2, 2019
@kpango
Copy link
Owner

kpango commented Oct 2, 2019

hmm 🤔
So you mean it crashed again at the same line of code?

@erebusdark
Copy link
Author

erebusdark commented Oct 2, 2019

Not exactly, I got this error this time:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x4 pc=0x12488]

goroutine 18 [running]:
github.com/kpango/fastime.(*Fastime).StartTimerD.func1(0x2084140, 0x4c4b40, 0x0, 0x2bf3c8, 0x206a9a0)
        /home/erebus/go/src/github.com/kpango/fastime/fastime.go:183 +0x70
created by github.com/kpango/fastime.(*Fastime).StartTimerD
        /home/erebus/go/src/github.com/kpango/fastime/fastime.go:180 +0xb4

@kpango kpango added the help wanted Extra attention is needed label May 29, 2020
@kpango
Copy link
Owner

kpango commented Jul 16, 2021

@erebusdark Hi, I apologize that this issue has been lying unsolved for a very long time.
I have just released fastime v1.0.17 and glg v1.6.2 which uses it, since the alignment issue was solved by #42.

You might not have already used them, but I'd like to give you a reminder.

@kpango kpango closed this as completed Jul 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants