Search code examples
springspring-retryretry-logic

RetryContext is not updated to exhausted=true, on reaching maxAttempts


Is there a bug in the spring-retry using retryTemplate ? I see that after the maxAttempts are reached, the retryContext should be updated to exhausted=true, but I still see it false as seen in the log below in my recovery method:

{"@timestamp":"2022-08-17T13:22:11.805+02:00","level":"INFO","message":"Rolled back with retryContext-[RetryContext: count=2, lastException=com.graph.Neo4jException, exhausted=false]"}

Since, the maxAttempts have been reached and the recoverymethod is triggered, should not exhaused=true?

Note: maxAttempts is set to 2. Please help!!


Solution

  • I think you misunderstand the purpose of exhausted.

    exhausted is a flag available to the user to terminate the retries early (for some reason) by calling setExhaustedOnly() on the context.

    The context has no knowledge about the max attempts so can't coerce the exhausted flag to true in its toString() (and shouldn't anyway because of its special meaning).