algorand / go-algorand-sdk

Algorand Golang SDK

Home Page:https://pkg.go.dev/github.com/algorand/go-algorand-sdk/v2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Algod client healtcheck method returns error although server returns 200

polarbit opened this issue · comments

Algod client's healtcheck method returns "json: Unmarshal(nil)" error ; although algod node returns success 200 (null).

The problem is: sdk tries to unmarshal node's healthcheck response; but the node returns http status 200 with "null" text content.

It can be fixed by unmarshaling the response only if provided response parameter is not null, at line 185 at file common.go

image

Your environment

go version: go1.17.6 darwin/amd64
algorand sdk: github.com/algorand/go-algorand-sdk v1.12.0

curl --location --request GET 'https://testnet-algorand.api.purestake.io/ps2/health' --header 'x-api-key: ***'

# Returns Status 200 (OK) with content "null"

Acceptance Criteria

  • Review the go code, the go v1 SDK and the other SDKs.
  • Avoid returning an error when there is no error.

This seems to work OK on v2.0.0:

// Create an algod client
algodClient, err := algod.MakeClient(algodAddress, algodToken)
if err != nil {
  fmt.Printf("failed to make algod client: %s\n", err)
  return
}

err := algodClient.HealthCheck().Do(context.Background())
fmt.Printf("algod health: %v\n", err)

returns: algod health: <nil>

Looks like this was indirectly fixed by #464

I took the program from @algochoi and modified a go.mod to try different versions. It was fixed in v1.14.1 which had the one fix in it.