Confusing for NewClient in 1.63
SamYuan1990 opened this issue · comments
Please see the FAQ in our main README.md before submitting your issue.
NewClient
Line 124 in c31cec3
but
Line 392 in c31cec3
// WithTimeout returns a DialOption that configures a timeout for dialing a
// ClientConn initially. This is valid if and only if WithBlock() is present.
//
// Deprecated: use DialContext instead of Dial and context.WithTimeout
// instead. Will be supported throughout 1.x.
hence, which means in 1.63 we Deprecated timeout support?
as I found this issue by lint Hyperledger-TWGC/tape#384
if I change to the NewClient following unit test case
Line 390 in c31cec3
Any suggestion?
Further more,
Lines 126 to 290 in c31cec3
as NewClient is going to replace DialContext,
the DialContext invokes Newclient and handle timeout out of NewClient... but from the code comments, it seems NewClient should handle timeout. But in fact it just handle idleTimeout
?
Setting a timeout when creating a client is an anti-pattern, and is not possible in any other gRPC implementations.
See https://github.com/grpc/grpc-go/blob/master/Documentation/anti-patterns.md#dialing-in-grpc for more info.
from the code comments, it seems NewClient should handle timeout
From which comments specifically? I'd like to cleanup the documentation as much as possible, so please let me know any places where you think it could be improved.
Setting a timeout when creating a client is an anti-pattern, and is not possible in any other gRPC implementations.
See https://github.com/grpc/grpc-go/blob/master/Documentation/anti-patterns.md#dialing-in-grpc for more info.
from the code comments, it seems NewClient should handle timeout
From which comments specifically? I'd like to cleanup the documentation as much as possible, so please let me know any places where you think it could be improved.
@dfawley , I suppose you are not get my point. I am not query on anti-pattern, or say if we apply the lint checking to current code. I am not sure if anti-pattern still works as for example WithTimeout is marked as Deprecated and the impl https://github.com/grpc/grpc-go/blob/master/clientconn.go#L244-L262 for timeout feature seems not anti-pattern ?
here are my steps, please go through them:
- the lint reports https://github.com/grpc/grpc-go/blob/master/clientconn.go#L200C4-L200C14 as Deprecated hence I go to NewClient https://github.com/grpc/grpc-go/blob/master/clientconn.go#L126 as here.
- at the NewClient, where https://github.com/grpc/grpc-go/blob/master/clientconn.go#L124-L125 seems I can use
WithTimeout
- but ...
Line 390 in c31cec3
so...
if I follow the NewClient hint, I will use WithTimeout as a Deprecated function then the lint fails again.
or
back to the 1st as following here https://github.com/grpc/grpc-go/blob/master/clientconn.go#L215 try to just use NewClient instead of DialContext which I found the timeout handle at https://github.com/grpc/grpc-go/blob/master/clientconn.go#L244-L262 which means the NewClient does not equals with DialContext and I can't replace it.
As the NewClient at https://github.com/grpc/grpc-go/blob/master/clientconn.go#L194 seems just handle cc.dopts.idleTimeout but not cc.dopts.Timeout, does it supports timeout ? if yes, why https://github.com/grpc/grpc-go/blob/master/clientconn.go#L244-L262 impls timeout by itself?
step further to learn from test case, https://github.com/grpc/grpc-go/blob/master/clientconn_test.go#L390 as https://github.com/grpc/grpc-go/blob/master/clientconn_test.go#L392 the WithTimeout is marked with Deprecated, the lint will fail, which not helpful.
at the NewClient, where master/clientconn.go#L124-L125 seems I can use
WithTimeout
I'm not sure why you think it says you can use WithTimeout
. It explicitly says the opposite exactly where you quoted it:
The DialOptions returned by WithBlock, WithTimeout, and WithReturnConnectionError are ignored by this function.
Feel free to make your linter ignore these deprecated functions. We will not be removing them.
But your best bet is to read and follow https://github.com/grpc/grpc-go/blob/master/Documentation/anti-patterns.md#dialing-in-grpc and stop using both Dial
and WithTimeout
. It will give you more consistent behavior with other languages and ensure you have proper error handling around where RPCs are occurring.
If you have specific parts of the documentation that you can point to that need to be updated, I'd appreciate it. We can cover that in #7049.