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

Add StreamMessage.timeout() #5761

Merged
merged 28 commits into from
Nov 7, 2024
Merged

Conversation

sjy982
Copy link
Contributor

@sjy982 sjy982 commented Jun 13, 2024

Motivation:
Currently, the aggregate() and subscribe() methods of StreamMessage do not have the ability to set a timeout. This provides the ability to detect when a client or server has not responded for a period of time and handle it appropriately. Additionally, the timeout API can be used to detect idle streams by setting a timeout until the next message.

Modifications:

  1. Added the TimeoutStreamMessage class
  • Wrap a StreamMessage to provide timeout functionality
  • You can set a timeout feature by adding the timeout() method to the StreamMessage interface.
  1. Added the TimeoutSubscriber class
  • Schedule a timeout for each message.
  • StreamTimeoutMode allows you to set different timeout modes.
  1. Added StreamTimeoutMode enumeration
  • Defines the UNTIL_FIRST, UNTIL_NEXT, and UNTIL_EOS modes.
  1. Added a timeout method
  • Added the timeout method to the StreamMessage, HttpResponse, and HttpRequest interfaces to provide the ability to set a timeout.

Result:

  • Closes Add StreamMessage.timeout() #5744
  • This change adds timeout functionality to the aggregate() and subscribe() methods of StreamMessage and HTTP requests/responses.
  • This allows idle streams to be detected and handled appropriately.
  • You can use StreamTimeoutMode to set the timeout between the arrival of the first message, the arrival of the next message, or the end of the stream.

@CLAassistant
Copy link

CLAassistant commented Jun 13, 2024

CLA assistant check
All committers have signed the CLA.

@Bue-von-hon
Copy link
Contributor

Some of the descriptions in the Modifications field contain Korean.

Added StreamTimeoutMode enumeration
UNTIL_FIRST, UNTIL_NEXT, UNTIL_EOS 모드를 정의합니다.

p.s. It's an interesting feature, so I'm watching with interest

@sjy982 sjy982 requested a review from trustin June 24, 2024 13:22
@sjy982
Copy link
Contributor Author

sjy982 commented Jun 24, 2024

Some of the descriptions in the Modifications field contain Korean.

Added StreamTimeoutMode enumeration
UNTIL_FIRST, UNTIL_NEXT, UNTIL_EOS 모드를 정의합니다.

p.s. It's an interesting feature, so I'm watching with interest

Thank you for your interest.

Copy link
Member

@trustin trustin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Please make the build pass as well.

@trustin
Copy link
Member

trustin commented Jun 25, 2024

Last but not least, please sign the ICLA.

@sjy982
Copy link
Contributor Author

sjy982 commented Jun 25, 2024

Last but not least, please sign the ICLA.

I checked, thank you for your review.

@sjy982 sjy982 force-pushed the feature/stream-message-timeout branch from 7c52cef to d1ea297 Compare June 25, 2024 15:37
Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly done 👍 Left a couple of comments regarding edge cases

Unsubscribing due to a timeout does not guarantee synchronization with upstream.

Therefore, we implemented an attempt attemptTerminate() method.
Lint error correction
Copy link
Member

@minwoox minwoox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Left a few suggestions. 👍

1. remove @throws from docs
2. add @UnstableApi with timeout method
3. public -> final
4. add @nullable to timeoutSubscriber
5. cancel() override (add cancelSchedule())
6. lastontime nano -> lasteventtime nano
7. createTimeoutSchedule -> scheduleTimeout
8. call onError after canceling
Copy link
Member

@minwoox minwoox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still Looks good. 👍 Left a few more suggestions.

@minwoox minwoox marked this pull request as ready for review July 5, 2024 07:22
@minwoox minwoox requested a review from ikhoon as a code owner July 5, 2024 07:22
Copy link
Member

@minwoox minwoox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few more suggestions. 😉

2. add docs to StreamTimeoutMode parameter
3. use test code executor.get()
…and set the timeout schedule

2. change TimeoutSubscriber class to TimeoutStreamMessage's inner class
@sjy982 sjy982 requested a review from minwoox July 8, 2024 11:25
Copy link
Member

@minwoox minwoox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks a lot, @sjy982! 😆

@sjy982 sjy982 force-pushed the feature/stream-message-timeout branch from 251daf7 to 73adfff Compare July 8, 2024 13:20
Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some nit comments, basically looks good 👍 👍 👍

…meoutMode`

2. Added leak prevention code when completed in onNext() - PooledObjects.close(t)
@sjy982 sjy982 requested a review from jrhee17 July 11, 2024 07:47
Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to revise and proofread Javadoc but the implementation looks look.

2. Add a StreamTimeoutException
3. Overriding WebSocket's timeout method
4. Remove cancelSchedule() from abort()
5. Set timeoutFuture to null to avoid calling .isCancelled() which may access a volatile field.
6. Modify boolean cancels to volatile boolean cancels
@sjy982 sjy982 requested a review from ikhoon July 17, 2024 11:34
Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, @sjy982! 💯🚀

@ikhoon ikhoon modified the milestones: 1.30.0, 1.31.0 Aug 1, 2024
@github-actions github-actions bot added the Stale label Sep 1, 2024
@github-actions github-actions bot removed the Stale label Nov 7, 2024
@jrhee17 jrhee17 merged commit 1bb781a into line:main Nov 7, 2024
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add StreamMessage.timeout()
7 participants