Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add http rpc timeout option as per (#23416) #23483

Closed
wants to merge 5 commits into from
Closed

Conversation

reds
Copy link
Contributor

@reds reds commented Aug 28, 2021

No description provided.

Name: "http.timeout",
Usage: "Sets http rpc request timeout (use \"s\" suffix for seconds, eg: --http.timeout 10s)",
// uses time.ParseDuration() which requires a unit suffix, "h", "m", "s", "ms" etc.
Value: fmt.Sprint(ethconfig.Defaults.HTTPRpcTimeout.Nanoseconds(), "ns"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have (or time lib) have some nicer default printer? It seems a bit silly to print the default in nano-seconds, nicer to have it in seconds or milliseconds.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or even better -- IIRC there's some DurationFlag type, isn't there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, just printing it out does a better job. 5s instead of 5...ns.

There is a DurationFlag type, nice.

@@ -972,7 +972,11 @@ func (e *revertError) ErrorData() interface{} {
// Note, this function doesn't make and changes in the state/blockchain and is
// useful to execute and retrieve values.
func (s *PublicBlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride) (hexutil.Bytes, error) {
result, err := DoCall(ctx, s.b, args, blockNrOrHash, overrides, 5*time.Second, s.b.RPCGasCap())
timeout := s.b.HTTPRpcTimeout()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the only place where we use this? Seems odd, if we have a 'global' rpctimeout flag, to only ever apply it on the Call method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going through internal/ethapi/api.go it seems to be the only rpc with that hard coded timeout. I'll dig in some more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There also this:

Service: filters.NewPublicFilterAPI(s.APIBackend, false, 5*time.Minute),

A hard coded 5 minute timeout for filters api, eth_getLogs, eth_getFilterChanges etc. Seems incompatible with the 5 second timeout for eth_call.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the same kind of timeout -- filters generally live on a ws subscription, not a one-off http request/response pair.

@reds reds requested a review from holiman September 13, 2021 20:01
}
timeout, err := time.ParseDuration(arg)
if err != nil {
log.Warn("Bad http.timeout setting", arg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our log facilities are a bit peculiar: essentially it's on the form log.Level( <message>, <key-name>, <value>, <key-name>, <value>). So it's always 1 + 2N arguments. In this case, it would be appropriate with e.g. log.Warn("Failed to parse http timeout duration", "err", err)

Comment on lines +1610 to +1614
arg := ctx.GlobalString(HTTPRpcTimeoutFlag.Name)
_, err := strconv.Atoi(arg)
if err == nil {
arg = arg + "ns"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why parse, it's a Duration type already ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I cleaned this up and added some tests.

@fjl
Copy link
Contributor

fjl commented Sep 28, 2021

Closing in favor of #23645.

@fjl fjl closed this Sep 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants