BuildOnViction / victionchain

The Efficient Blockchain Powered By Proof Of Stake Voting Consensus
https://viction.xyz
GNU Lesser General Public License v3.0
168 stars 85 forks source link

Fix some rpc bugs #406

Closed trinhdn2 closed 11 months ago

trinhdn2 commented 11 months ago

RPC API calls usually are cancelled too early such as WARN [04-10|05:33:03.071] Served eth_getBlockByNumber conn=127.0.0.1:46600 reqid=1 t=262.386μs err="context canceled" Also when cancelling the context for a call on a HTTP-based client while the call is running, the select in requestOp.wait may hit the <-context.Done() case instead of the <-op.resp case. This doesn't happen often -- our cancel test hasn't caught this even though it ran thousands of times on CI since the RPC client was added.

This PR makes sure to cancel the root context passed by RPC calls after all the requests are served and fix the rare deadlock when cancelling HTTP call context.

Prerequisites:

References: