Closed satindergrewal closed 4 years ago
Recieved the same error while testing Shurli on Windows.
Had DEX chain started, and PIRATE stopped, and following error was printed on console output of shurli if ran with shurli.exe main
:
2020/07/05 00:19:02 http: panic serving 127.0.0.1:50152: runtime error: invalid memory address or nil pointer dereference
goroutine 208 [running]:
net/http.(*conn).serve.func1(0xc0004fad20)
/usr/local/Cellar/go/1.14.4/libexec/src/net/http/server.go:1772 +0x140
panic(0x8566e0, 0xc4c960)
/usr/local/Cellar/go/1.14.4/libexec/src/runtime/panic.go:975 +0x3f1
github.com/satindergrewal/kmdgo.AppType.APICall(0xc00045b868, 0x6, 0xc0001d0e18, 0xc00045bc28, 0x0)
/Users/satinder/go/src/github.com/satindergrewal/kmdgo/common.go:134 +0x62c
github.com/satindergrewal/kmdgo.AppType.GetInfo(0xc00045b868, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
/Users/satinder/go/src/github.com/satindergrewal/kmdgo/control.go:71 +0xf3
github.com/Meshbits/shurli/sagoutil.WalletInfo(0xc00008ee00, 0x5, 0x8, 0xc00008ee00, 0x5, 0x8)
/Users/satinder/go/src/github.com/Meshbits/shurli/sagoutil/sago_lib.go:80 +0x288
main.idx(0x980b40, 0xc00047e700, 0xc000133a00)
/Users/satinder/go/src/github.com/Meshbits/shurli/main.go:296 +0xa9
net/http.HandlerFunc.ServeHTTP(0x8fc0b8, 0x980b40, 0xc00047e700, 0xc000133a00)
/usr/local/Cellar/go/1.14.4/libexec/src/net/http/server.go:2012 +0x4b
github.com/gorilla/mux.(*Router).ServeHTTP(0xc000282000, 0x980b40, 0xc00047e700, 0xc000133800)
/Users/satinder/go/src/github.com/gorilla/mux/mux.go:210 +0xe9
net/http.serverHandler.ServeHTTP(0xc00029e0e0, 0x980b40, 0xc00047e700, 0xc000133800)
/usr/local/Cellar/go/1.14.4/libexec/src/net/http/server.go:2807 +0xaa
net/http.(*conn).serve(0xc0004fad20, 0x981440, 0xc000095a40)
/usr/local/Cellar/go/1.14.4/libexec/src/net/http/server.go:1895 +0x873
created by net/http.(*Server).Serve
/usr/local/Cellar/go/1.14.4/libexec/src/net/http/server.go:2933 +0x363
Due to this error, the web UI was failing to load. Just starting back PIRATE, even if it's in loading state, the web UI responded fine.
To replicate, I just start import process of address in komodod with importprivkey
command and then test by executing example file getinfo.go from kmdgo package which just queries the komodo-cli getinfo
API. And as it is busy and doesn't respond while importing and doing full rescan of blockchain, it throws the following output for invalid memory address error:
➜ examples git:(master) ✗ go run getinfo.go
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x48 pc=0x1283f15]
goroutine 1 [running]:
github.com/satindergrewal/kmdgo.AppType.APICall(0x131945e, 0x6, 0xc00014f958, 0x8905c00, 0x20300000000000)
/Users/satinder/go/src/github.com/satindergrewal/kmdgo/common.go:135 +0x625
github.com/satindergrewal/kmdgo.AppType.GetInfo(0x131945e, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
/Users/satinder/go/src/github.com/satindergrewal/kmdgo/control.go:71 +0xec
main.main()
/Users/satinder/go/src/github.com/satindergrewal/kmdgo/examples/getinfo.go:51 +0xac
exit status 2
➜ examples git:(master) ✗
I found that I have not applied proper error check for API response body in common.go line 134: https://github.com/satindergrewal/kmdgo/blob/master/common.go#L134
bodyText, err := ioutil.ReadAll(resp.Body)
This causing the issue. Working on its fix now.
This link helped with the error: https://stackoverflow.com/questions/53926818/invalid-memory-address-in-golang-using-ioutil-readall
Fixed issue by extending error handling for:
resp, err := client.Do(req)
Added error handling for context deadline exceeded
and also adding any other error handling to end the code execution further. In my current tests it fixed the issue with this git commit: https://github.com/satindergrewal/kmdgo/commit/22e72f9aa7caa20bb80f276a24968f8036175236
Can report back if the same issue arise again somehow.
If any coin's RPC Is busy and fails to respond with RPC query, gRPC calls throws pointer dereference errors and exit the process.