KEMBAR78
RetryGatewayFilterFactory RetryConfig support Jitter & Timeout by JoeCqupt · Pull Request #3713 · spring-cloud/spring-cloud-gateway · GitHub
Skip to content

Conversation

@JoeCqupt
Copy link
Contributor

@JoeCqupt JoeCqupt commented Mar 7, 2025

@JoeCqupt
Copy link
Contributor Author

JoeCqupt commented Mar 7, 2025

PTAL @spencergibb

@ryanjbaxter
Copy link
Contributor

Can you add documentation and tests?

@ryanjbaxter
Copy link
Contributor

Also it would be good to have his PR made against the 4.1.x branch

@JoeCqupt JoeCqupt changed the base branch from main to 4.1.x March 12, 2025 05:29
@JoeCqupt JoeCqupt force-pushed the main branch 2 times, most recently from 96eac94 to 442325f Compare March 12, 2025 07:47
Signed-off-by: jiangyuan <joe469391363@gmail.com>
Signed-off-by: jiangyuan <joe469391363@gmail.com>
Signed-off-by: jiangyuan <joe469391363@gmail.com>
public void retryWithBackoffTimeout() {
// backoff > timeout
testClient.get()
.uri("/retry?key=retry-with-backoff-timeout&count=3")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain how hitting /retry tests timeouts?

It looks like all this endpoint does is immediately return a 500
https://github.com/spring-cloud/spring-cloud-gateway/pull/3713/files#diff-a2252bbc8510b2b95c8edffb04415464d9b1c5840d8069753726236cf771d71dR346-R360

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://github.com/spring-cloud/spring-cloud-gateway/pull/3713/files#diff-a2252bbc8510b2b95c8edffb04415464d9b1c5840d8069753726236cf771d71dR394-R398

route:retry_with_backoff_timeout_test config:
retries:3
firstbackoff: 100ms factor:2
timeout 100ms

The final calculation result will result in backoff>timeout

Copy link
Contributor

Choose a reason for hiding this comment

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

But /httpbin/retry will never take 100ms it just immediately returns a 500 based on count
https://github.com/spring-cloud/spring-cloud-gateway/pull/3713/files#diff-a2252bbc8510b2b95c8edffb04415464d9b1c5840d8069753726236cf771d71dL322-L342

It seems like you would want to use /httpbin/sleep to test timeout functionality.

Copy link
Contributor Author

@JoeCqupt JoeCqupt Mar 18, 2025

Choose a reason for hiding this comment

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

yes /httpbin/retry will return 500 immediately.

but i set backoff config. firstbackoff will delay 100ms . and backoff will increase exponential(factor 2).

i update the unit test to verfiy TestConfig.map key retry-with-backoff-timeout value is 2 .
this proves that after the first retry, the backoff will be greater than timeout, retry will terminate and then return the current response.

	@Test
	public void retryWithBackoffTimeout() {
		// backoff > timeout
		testClient.get()
			.uri("/retry?key=retry-with-backoff-timeout&count=3")
			.header(HttpHeaders.HOST, "www.retrywithbackofftimeout.org")
			.exchange()
			.expectStatus()
			.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
		assertThat(TestConfig.map.get("retry-with-backoff-timeout")).isNotNull().hasValue(2);
	}

route config:

				.route("retry_with_backoff_timeout_test", r -> r.host("**.retrywithbackofftimeout.org")
					.filters(f -> f.prefixPath("/httpbin").retry(config -> {
						config.setRetries(3)
							.setBackoff(Duration.ofMillis(100), null, 2, true)
							.setTimeout(Duration.ofMillis(200));
					}))
					.uri(uri))

Signed-off-by: joecqupt <joe469391363@gmail.com>
Signed-off-by: jiangyuan <joe469391363@gmail.com>
@ryanjbaxter
Copy link
Contributor

Sorry this was my fault. I did not realize this timeout was for the backoff itself. I appreciate your patience with my questioning.

@ryanjbaxter ryanjbaxter added this to the 4.1.7 milestone Mar 20, 2025
@ryanjbaxter ryanjbaxter merged commit c21ea88 into spring-cloud:4.1.x Mar 20, 2025
2 checks passed
@github-project-automation github-project-automation bot moved this to Done in 2023.0.6 Mar 20, 2025
@spencergibb spencergibb moved this to Done in 2024.0.2 Jul 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

No open projects
Status: Done
Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants