You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Client timeout of 0 causes immediate "context deadline exceeded" #126
This is arguably a duplicate of #14 which pointed out a doc deficiency and was addressed by telling the user to use operations.New*Params() functions.
It's also arguably a duplicate of go-swagger/go-swagger#919 where somebody else stumbled into the same problem. @casualjim responded that "We need a way to express forever because there are certain cases where you really don't want a request to timeout.", "... you want the connection to be opened forever, forever is signaled by using 0" and the case was closed.
Unless I'm misunderstanding something that seems to be a mistake as the code doesn't operate that way.
I think the hasTimeout var should only be set true if request.timeout is non-zero.
Reacted by sue mynott, Beoran, Aidan Steele, braun1928, Andreas Leeb, Hugues Malphettes, Alan, Soumya Kanti Roy chowdhury, Jingchao, Said Saifi and 2 more
Does the suggested solution have any drawbacks? As the current code also causes an issue where the timeout is not respected. So if you have both context set and timeout parameter set then the timeout will just be ignored. For example:
Issue
// let's assume that we have a ctx defined before that did not have a deadlineparams:=NewAddOneParamsWithContext(ctx)
params.SetTimeout(10*time.Second)
// calling AddOne which will then call Submit function
c.AddOne(params, ...)
The existing code will not respect the timeout as the context is set.
Workaround
A workaround is to pass the timeout in the context, so you can instead do:
// let's assume that we have a ctx defined before that did not have a deadlinectx, cancel:=context.WithTimeout(ctx, 10*time.Second)
defercancel()
params:=NewAddOneParamsWithContext(ctx)
// calling AddOne which will then call Submit function
c.AddOne(params, ...)
Possible solution 1:
If we want to always prioritize request.timeout even if context has already a deadline. (May not be a good idea as we will not respect the existing context deadline).
Activity
said-saifi commentedon Jun 1, 2021
Does the suggested solution have any drawbacks? As the current code also causes an issue where the timeout is not respected. So if you have both context set and timeout parameter set then the timeout will just be ignored. For example:
Issue
The existing code will not respect the timeout as the context is set.
Workaround
A workaround is to pass the timeout in the context, so you can instead do:
Possible solution 1:
If we want to always prioritize request.timeout even if context has already a deadline. (May not be a good idea as we will not respect the existing context deadline).
Possible solution 2:
Only assuming timeout exists if context has a deadline and that's less than the request timeout. Any drawbacks for this solution?
youyuanwu commentedon Jun 5, 2021
"Possible solution 1" above is ok. "Possible solution 2" is not standard of how to handle ctx in Go.
fixed immediate timeout
fixed immediate timeout
fixed immediate timeout