armeria
armeria copied to clipboard
Add `StreamMessage.timeout()`
Currently, there is no timeout for StreamMessage's aggregate() or subscribe(). If we want to give a timeout for HttpRequest.aggregate(), a separate scheduler needs to be run to abort the request if it is not completed within the given time.
The timeout API can also be used to detect an idle stream by setting a timeout until the next message. https://github.com/line/armeria/pull/5713#issuecomment-2150498394
enum StreamTimeoutMode {
UNTIL_FIRST,
// Maybe the default one
UNTIL_NEXT,
UNTIL_EOS // or UNTIL_LAST
}
StreamMessage<Object> stream = ...;
// Sets a timeout for each message to 5 seconds.
stream.timeout(5_seconds).subscribe(....);
// UNTIL_EOS will be useful for unary requests.
HttpRequest req = ...;
req.timeout(StreamTimeoutMode.UNTIL_EOS, 10_seconds).aggregate();
req.aggregate(10_seconds); // Shortcut
// UNTIL_NEXT will be useful for stream requests such as gRPC streams or WebSocket.
WebSocket input = ...;
input.timeout(UNTIL_NEXT, 3_seconds).subscribe(...);
I'm in charge of this issue.
Yes, please. 🙇