Comments (4)
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
?
from grpc-go.
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.
from grpc-go.
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.
from grpc-go.
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.
from grpc-go.
Related Issues (20)
- User agent becomes grpc-go/1.64. on server side of grpc gateway HOT 3
- xds: move functionality from `xds/internal` to `internal/xds`
- stubserver: add support to optionally pass in a `grpc.Server` or `xds.GRPCServer` HOT 2
- Github Action: Codecov action is broken and is failing silently HOT 1
- Upgrade to using math/rand/v2 to get perf enhancements HOT 2
- xds: tests shouldn't rely on the presence of an entry in the `authorities` field of the bootstrap configuration with an empty key
- Experimental API related to metadata HOT 4
- Linter rule for using context.Background() without a timeout in tests HOT 4
- gRPC is incompatible with tls.Listener HOT 2
- Closing connection takes up to 15 minutes. HOT 5
- Feature Request: expose handleRawConn or add ServeConn HOT 26
- Flaky test: TimerAndWatchStateOnErrorCallback HOT 4
- xds: bootstrap config is not emitted to logs in a human readable way
- Strongly-type request inside a Stream Server Interceptor HOT 2
- Proxy connection buffer necessary? HOT 1
- Why does grpc.NewClient silently ignore DialOptions? HOT 2
- Make transport.SetConnection public? HOT 4
- what's the default max data size
- If a priority contains multiple localities with pick_first, load is reported incorrectly HOT 4
- NewClient doesn't work with WithContextDialer HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grpc-go.