redwood icon indicating copy to clipboard operation
redwood copied to clipboard

Variable "timeout"

Open UnveilTech opened this issue 3 years ago • 2 comments

Hello Andy, exploring the source code it seems the "Timeout" is hard-coded to 30 sec for the connection, correct ? would it be possible to add a variable "timeout" in the "config.go" (applied to tls.go and/or transport.go) in order to increase/decrease the connection timeout ? we mainly use Redwood as Classification Service to get the category and 30 sec is an issue as we need to get the answer as fast as possible...

thanks in advance :o) Bye Fred

UnveilTech avatar Apr 06 '23 06:04 UnveilTech

I don't think the classification service uses either of those timeouts, because it uses http.DefaultClient. You could set up an http.Client that uses a dialer with a custom timeout, but it might actually be better to set a higher-level timeout on the request context.

You could replace NewRequest with NewRequestWithContext, something like this:

-     req, err := http.NewRequest("GET", url, nil)
+     req, err := http.NewRequestWithContext(context.WithTimeout(r.Context(), conf.ClassifyTimeout), "GET", url, nil)

andybalholm avatar Apr 06 '23 16:04 andybalholm

thanks Andy, we'll try ;o)

UnveilTech avatar Apr 07 '23 11:04 UnveilTech