Skip to content

Commit a3a9ffc

Browse files
docs: Correct the manual flow control README regarding onNext blocking (#12700)
### Description This PR updates the "Outgoing Flow Control" section in the Manual Flow Control example's README. The previous documentation incorrectly implied that calling `onNext()` on a stream would block if the underlying Netty buffer was full, thereby limiting the send rate. This PR clarifies that `onNext()` does *not* block, but rather queues the messages in memory, which can ultimately lead to an `OutOfMemoryError` if messages are sent too quickly. The updated text correctly advises developers to use `CallStreamObserver.isReady()` to prevent this memory exhaustion, rather than to avoid blocking. Fixes #12657 --------- Co-authored-by: Kannan J <kannanjgithub@google.com>
1 parent 91e9491 commit a3a9ffc

File tree

1 file changed

+5
-11
lines changed
  • examples/src/main/java/io/grpc/examples/manualflowcontrol

1 file changed

+5
-11
lines changed

examples/src/main/java/io/grpc/examples/manualflowcontrol/README.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
gRPC Manual Flow Control Example
2-
=====================
1+
# gRPC Manual Flow Control Example
2+
33
Flow control is relevant for streaming RPC calls.
44

55
By default, gRPC will handle dealing with flow control. However, for specific
@@ -25,14 +25,7 @@ value.
2525

2626
### Outgoing Flow Control
2727

28-
The underlying layer (such as Netty) will make the write wait when there is no
29-
space to write the next message. This causes the request stream to go into
30-
a not ready state and the outgoing onNext method invocation waits. You can
31-
explicitly check that the stream is ready for writing before calling onNext to
32-
avoid blocking. This is done with `CallStreamObserver.isReady()`. You can
33-
utilize this to start doing reads, which may allow
34-
the other side of the channel to complete a write and then to do its own reads,
35-
thereby avoiding deadlock.
28+
The underlying layer (such as Netty) manages a buffer for outgoing messages. If you write messages faster than they can be sent over the network, this buffer will grow, which can eventually lead to an OutOfMemoryError. The outgoing onNext method invocation does not block when this happens. Therefore, you should explicitly check that the stream is ready for writing via `CallStreamObserver.isReady()` before calling onNext to avoid buffering excessive amounts of data in memory.
3629

3730
### Incoming Manual Flow Control
3831

@@ -71,6 +64,7 @@ When you are ready to begin processing the next value from the stream call
7164
`serverCallStreamObserver.request(1)`
7265

7366
### Related documents
67+
7468
Also see [gRPC Flow Control Users Guide][user guide]
7569

76-
[user guide]: https://grpc.io/docs/guides/flow-control
70+
[user guide]: https://grpc.io/docs/guides/flow-control

0 commit comments

Comments
 (0)