0chain / gosdk

A client SDK in Go to interface the blockchain and storage platform, and other smart contracts
MIT License
32 stars 29 forks source link

response body not returned as error when dominant sharder response is not 200 #534

Closed avanaur closed 2 years ago

avanaur commented 2 years ago

response body not returned as error when dominant sharder response is not 200.

https://github.com/0chain/gosdk/blob/70a96ae85bff57245604f5ff6cd7e262519074f4/zboxcore/zboxutil/http.go#L570

the content of error was being set from last received response from sharder. for example, below shows the added error was from good response. the next example is able to show error correctly

with good response as error

allocation_fetch_error: Error fetching the allocation.{"id":"41ab2b1715356a8e5df41b354ad47ed59e42827721cd822fe9972d4d37966d3f","tx":"41ab2b1715356a8e5df41b354ad47ed59e42827721cd822fe9972d4d37966d3f","data_shards":1,"parity_shards":1,"size":10485760,"expiration_date":1660232463,"owner_id":"69c262886ce856ca8397d6fceb8b6388a8c8cda7c9424eafa96ab58a930e19f5","owner_public_key":"0468ef36a1e7879182b8f4fcaf7c09b7316701c5ffe504b44f554a622075780b2ad344cba881e42fe84d0a0f133fa39fedb714462b333f04c1e97b9705e8b00c","stats":{"used_size":0,"num_of_writes":0,"num_of_reads":0,"total_challenges":0,"num_open_challenges":0,"num_success_challenges":0,"num_failed_challenges":0,"latest_closed_challenge":""},"diverse_blobbers":false,"preferred_blobbers":null,"blobber_details":[{"blobber_id":"c50ebe28f8a8aad4e9205030533765887f4449b9cf250ad0315c9d4afa9b4ef7","allocation_id":"41ab2b1715356a8e5df41b354ad47ed59e42827721cd822fe9972d4d37966d3f","size":16038821300,"allocation_root":"","write_marker":null,"stats":null,"terms":{"read_price":100000000,"write_price":1000000000,"min_lock_demand":0.1,"max_offer_duration":2678400000000000},"min_lock_demand":16276,"spent":0,"penalty":0,"read_reward":0,"returned":0,"challenge_reward":0,"final_reward":0,"challenge_pool_integral_value":0,"blobber_allocs_partition_loc":null},{"blobber_id":"eae9a0ea2fd06645f8cdb3175a23999054f01ae1a7edd06847acd0548cbeee78","allocation_id":"41ab2b1715356a8e5df41b354ad47ed59e42827721cd822fe9972d4d37966d3f","size":20463812020,"allocation_root":"","write_marker":null,"stats":null,"terms":{"read_price":100000000,"write_price":1000000000,"min_lock_demand":0.1,"max_offer_duration":2678400000000000},"min_lock_demand":16276,"spent":0,"penalty":0,"read_reward":0,"returned":0,"challenge_reward":0,"final_reward":0,"challenge_pool_integral_value":0,"blobber_allocs_partition_loc":null}],"is_immutable":false,"third_party_extendable":false,"file_options":0,"write_pool":5000000000,"read_price_range":{"min":0,"max":9223372036854775807},"write_price_range":{"min":0,"max":9223372036854775807},"challenge_completion_time":0,"start_time":1660146063,"time_unit":2592000000000000,"curators":[],"name":"","blobbers":[{"id":"c50ebe28f8a8aad4e9205030533765887f4449b9cf250ad0315c9d4afa9b4ef7","url":"https://hightps-2.devnet-0chain.net/blobber02","geolocation":{"latitude":0,"longitude":0},"terms":{"read_price":100000000,"write_price":1000000000,"min_lock_demand":0.1,"max_offer_duration":2678400000000000},"capacity":337589997568,"allocated":16038821300,"last_health_check":1660146151,"saved_data":0,"data_read_last_reward_round":0,"last_reward_data_read_round":0,"stake_pool_settings":{"delegate_wallet":"9c693cb14f29917968d6e8c909ebbea3425b4c1bc64b6732cadc2a1869f49be9","min_stake":10000000000,"max_stake":1000000000000,"num_delegates":50,"service_charge":0.3},"reward_partition":{"index":0,"start_round":0,"timestamp":0},"info":{"name":"","website_url":"","logo_url":"","description":""}},{"id":"eae9a0ea2fd06645f8cdb3175a23999054f01ae1a7edd06847acd0548cbeee78","url":"https://hightps-2.devnet-0chain.net/blobber04","geolocation":{"latitude":0,"longitude":0},"terms":{"read_price":100000000,"write_price":1000000000,"min_lock_demand":0.1,"max_offer_duration":2678400000000000},"capacity":337515417600,"allocated":20463812020,"last_health_check":1660146177,"saved_data":0,"data_read_last_reward_round":0,"last_reward_data_read_round":0,"stake_pool_settings":{"delegate_wallet":"9c693cb14f29917968d6e8c909ebbea3425b4c1bc64b6732cadc2a1869f49be9","min_stake":10000000000,"max_stake":1000000000000,"num_delegates":50,"service_charge":0.3},"reward_partition":{"index":0,"start_round":0,"timestamp":0},"info":{"name":"","website_url":"","logo_url":"","description":""}}]}

with actual error

allocation_fetch_error: Error fetching the allocation.internal_error: can't get allocation: error retrieving allocation: 47e4250e012b40d914aea81be8b5bbfcd0befb98463a5b2b9ff761bb7ea762af, error: failed to connect to host=helm-sharder-postgres-02 user=zchain_user database=events_db: server error (FATAL: remaining connection slots are reserved for non-replication superuser connections (SQLSTATE 53300))

avanaur commented 2 years ago

This seems to be an issue as well for when dominant response is 200 but the last response received from sharder is from a non-200. The non-200 response (error) will be used as the 200 response.