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

Throw wrapped TimeoutException on Mono.block* and Flux.block* #3733

Merged

Conversation

injae-kim
Copy link
Contributor

Throw wrapped TimeoutException on Mono.block* and Flux.block* so that user can use this when timeout instead of digging into IllegalStateException message.

Fixes #3709.

Throw wrapped `TimeoutException` on `Mono.block*` and `Flux.block*` so that user can use this when timeout instead of digging into IllegalStateException message.

Fixes reactor#3709.
@injae-kim injae-kim requested a review from a team as a code owner February 22, 2024 16:33
Comment on lines +128 to +129
String errorMessage = "Timeout on blocking read for " + timeout + " " + unit;
throw new IllegalStateException(errorMessage, new TimeoutException(errorMessage));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

public final T blockFirst(Duration timeout) {

public final T blockLast(Duration timeout) {

I checked that Mono#block(timeout), Flux#blockFirst(timeout), Flux#blockLast(timeout) use this code~!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

* If the provided timeout expires, a {@link RuntimeException} is thrown.

// AS-IS
If the provided timeout expires, a {@link RuntimeException} is thrown.

// TO-BE
If the provided timeout expires, a {@link RuntimeException} is thrown with {@link TimeoutException} as the cause.

(just curiosity) should we enhance document on Mono#block*, Flux#block* like above?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✅ update javadoc :)

Comment on lines +152 to +153
String errorMessage = "Timeout on blocking read for " + timeout + " " + unit;
throw new IllegalStateException(errorMessage, new TimeoutException(errorMessage));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

public Optional<T> blockOptional(Duration timeout) {

I checked that Mono.blockOptional(timeout) use this code~!

Copy link
Member

@chemicL chemicL left a comment

Choose a reason for hiding this comment

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

Thanks @injae-kim ! Great job. Do you mind adding the bit about the cause to the javadocs as you suggested?

Comment on lines +128 to +129
String errorMessage = "Timeout on blocking read for " + timeout + " " + unit;
throw new IllegalStateException(errorMessage, new TimeoutException(errorMessage));
Copy link
Member

Choose a reason for hiding this comment

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

Yes, please.

@@ -103,7 +104,8 @@ public void timeoutOptionalTimingOut() {
// Using sub-millis timeouts after gh-1734
assertThatExceptionOfType(IllegalStateException.class)
.isThrownBy(() -> source.blockOptional(Duration.ofNanos(100)))
.withMessage("Timeout on blocking read for 100 NANOSECONDS");
.withMessage("Timeout on blocking read for 100 NANOSECONDS")
.withCause(new TimeoutException("Timeout on blocking read for 100 NANOSECONDS"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Update the Javadoc too

Copy link
Member

@chemicL chemicL left a comment

Choose a reason for hiding this comment

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

Thank you, @injae-kim 👏

@chemicL chemicL merged commit 8331346 into reactor:main Mar 5, 2024
7 checks passed
@chemicL chemicL added this to the 3.6.4 milestone Mar 5, 2024
@chemicL chemicL added the type/enhancement A general enhancement label Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Timeout behavior in Mono.block(timeout)
3 participants