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

okhttp: detect transport executors with no remaining threads #11271

Closed
ejona86 opened this issue Jun 6, 2024 · 0 comments · Fixed by #11503
Closed

okhttp: detect transport executors with no remaining threads #11271

ejona86 opened this issue Jun 6, 2024 · 0 comments · Fixed by #11503

Comments

@ejona86
Copy link
Member

ejona86 commented Jun 6, 2024

We've seen some cases where users are providing fixed-size thread pools to OkHttpChannelBuilder.transportExecutor(). gRPC provides no guarantees how many threads it may need, and queuing a Runnable can prevent transports from functioning.

In particular, grpc-okhttp needs two threads per transport: a reading thread and a sending thread. The reading thread runs for the life of the transport, but the sending thread is only used when something is actively needing to be written to the socket. During handshaking, however, only the reading thread is used, as there's no need to read and write simultaneously. This means the transport can start, but then no RPCs could actually be sent on it, because there are no more threads available.

It seems worthwhile to detect when the executor is misconfigured with too few threads, especially when happy eyeballs is enabled. To do this, during handshaking, we can start a second ("unnecessary") thread and have it blocked doing nothing until the handshake is complete. In addition, the handshake would be blocked on that thread getting scheduled (the Runnable.run() being executed). If it isn't scheduled in X time, then we abort the handshake and kill the transport. If the transport executor is only used for grpc-okhttp, this would guarantee there's at least one free thread to use for writing once the transport is ready and RPCs write data amongst all the transports.

@ejona86 ejona86 added this to the Next milestone Jun 6, 2024
@ejona86 ejona86 modified the milestones: Next, 1.68 Sep 16, 2024
kannanjgithub pushed a commit to kannanjgithub/grpc-java that referenced this issue Oct 23, 2024
Detect misconfigured transport executors with too few threads that could further throttle the transport.

Fixes grpc#11271
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants