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

New Sonyflake MachineID error #52

Open
kevinmiao opened this issue Apr 29, 2024 · 3 comments
Open

New Sonyflake MachineID error #52

kevinmiao opened this issue Apr 29, 2024 · 3 comments

Comments

@kevinmiao
Copy link

kevinmiao commented Apr 29, 2024

an error occurred when I new Sonyflake.
the file is github.com/sony/[email protected]/sonyflake.go.

i'm use MacOs 14.4.1.

After debugging, I found that the isPrivateIPv4() check ip error under lower16BitPrivateIP() method.
i not init MachineID when i new Sonyflake, so it will run this code :
var err error if st.MachineID == nil { sf.machineID, err = lower16BitPrivateIP(defaultInterfaceAddrs) } else { sf.machineID, err = st.MachineID() } if err != nil { return nil, err }

error Info
`
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x11a1e92]

goroutine 6 [running]:
testing.tRunner.func1.2({0x1265300, 0x14d52d0})
/usr/local/go/src/testing/testing.go:1545 +0x238
testing.tRunner.func1()
/usr/local/go/src/testing/testing.go:1548 +0x397
panic({0x1265300?, 0x14d52d0?})
/usr/local/go/src/runtime/panic.go:914 +0x21f
github.com/sony/sonyflake.(*Sonyflake).NextID(0x0)
/Users/pkg/mod/github.com/sony/[email protected]/sonyflake.go:116 +0x32

`

@YoshiyukiMineo
Copy link
Member

YoshiyukiMineo commented Apr 30, 2024

// NewSonyflake returns nil in the following cases:
// - Settings.StartTime is ahead of the current time.
// - Settings.MachineID returns an error.
// - Settings.CheckMachineID returns false.

So, if you would like to check the error, you should use func New(st Settings) (*Sonyflake, error) instead of NewSonyflake.

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

No branches or pull requests

3 participants
@YoshiyukiMineo @kevinmiao and others