amplitude / analytics-go

Go Amplitude Analytics SDK
MIT License
12 stars 7 forks source link

SDK Panics whole application on resolve failure (nil pointer) #48

Closed pnegahdar closed 2 years ago

pnegahdar commented 2 years ago

Expected Behavior

Don't panic and kill application when Analytics sdk fails to connect/resolve amplitude.

Current Behavior

Application panics when it cannot resolve api2.amplitude.com.

5ae382-e637-4661-ac0b-ff29749707e9","library":"amplitude-go/0.0.7"}]}
amplitude-analytics - 2022/11/03 19:20:12 Error: HTTP request failed: Post "https://api2.amplitude.com/2/httpapi": dial tcp [::]:443: connect: connection refused
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x10 pc=0x104f689fc]

goroutine 19 [running]:
github.com/amplitude/analytics-go/amplitude/plugins/destination.(*amplitudeHTTPClient).send(0x14000324fc0, {{0x1052929ce, 0x20}, {0x14000326e00, 0x1, 0xc8}, 0x0})
        /Users/pnegahdar/Projects/go/pkg/mod/github.com/amplitude/analytics-go@v0.0.10/amplitude/plugins/destination/amplitude_http_client.go:92 +0x62c
github.com/amplitude/analytics-go/amplitude/plugins/destination.(*amplitudePlugin).sendEventsFromStorage(0x14000388000, 0x0)
        /Users/pnegahdar/Projects/go/pkg/mod/github.com/amplitude/analytics-go@v0.0.10/amplitude/plugins/destination/amplitude_plugin.go:130 +0x100
github.com/amplitude/analytics-go/amplitude/plugins/destination.(*amplitudePlugin).Setup.func1()
        /Users/pnegahdar/Projects/go/pkg/mod/github.com/amplitude/analytics-go@v0.0.10/amplitude/plugins/destination/amplitude_plugin.go:54 +0x158
created by github.com/amplitude/analytics-go/amplitude/plugins/destination.(*amplitudePlugin).Setup
        /Users/pnegahdar/Projects/go/pkg/mod/github.com/amplitude/analytics-go@v0.0.10/amplitude/plugins/destination/amplitude_plugin.go:47 +0x278
exit status 2

Possible Solution

Should be straight forward to find that nil pointer with the stack above. Happy to help if needed.

Steps to Reproduce

Try blackholing api2.amplitude.com in /etc/hosts or just fix the nil pointer blindly.

Environment

liuyang1520 commented 2 years ago

Hi @pnegahdar , thanks for reporting this! I have a PR open (https://github.com/amplitude/analytics-go/pull/49) for fixing this, will update once the fix is merged and released.

liuyang1520 commented 2 years ago

Fixed in https://pkg.go.dev/github.com/amplitude/analytics-go@v0.0.12, closing this, thank you for reporting this issue again!