rust-web3 icon indicating copy to clipboard operation
rust-web3 copied to clipboard

Detecting rate limiting and transport error codes

Open Mirko-von-Leipzig opened this issue 3 years ago • 4 comments

I am currently using eth_getLogs and will occasionally get rate limited. This would be indicated by an error code 429.

Judging by this code, this currently gets "exposed" as an error string

Err(Error::Transport(format!(
            "response status code is not success: {}",
            status
        )

Would it be possible to expose the plain code? This would make it far easier to match on.

--edit-- In addition, Infura adds additional information into the body, which would be useful to have. i.e. the number of seconds to backoff.

Mirko-von-Leipzig avatar Nov 04 '21 13:11 Mirko-von-Leipzig

I think ideally this kind of throttling should be handled by the transport layer itself. Obviously I'm also fine with exposing this as a typed error. I think Error::Transport would could hold an enum instead of a String?

tomusdrw avatar Nov 14 '21 21:11 tomusdrw

I think ideally this kind of throttling should be handled by the transport layer itself. I think it can so long as the retry-amount is configurable? I would likely want to log that it happened though.

In general I think exposing the error code and contents in an enum would be fine.

Mirko-von-Leipzig avatar Nov 15 '21 06:11 Mirko-von-Leipzig

Related: https://github.com/tomusdrw/rust-web3/pull/585

tomusdrw avatar Feb 02 '22 15:02 tomusdrw

I see 0.18.0 now returns this situation as a TransportError::Code(429) which is great.

One thing that is still missing (I think) is getting the accompanying payload message. Some servers will set the back off time or other useful information.

For example, Infura returns 429 plus a json RPC payload which contains the back off time and current rate-limiting.

Infura rate limit docs: https://docs.infura.io/infura/networks/ethereum/how-to/secure-a-project/set-rate-limits#how-do-i-know-if-im-being-rate-limited

Mirko-von-Leipzig avatar Feb 25 '22 08:02 Mirko-von-Leipzig