spring-cloud/spring-cloud-openfeign

Prevent duplicate cache error handler execution in Feign clients

Bug FixApril 2, 2026Open

Contribution Overview

The Engineering Context

This contribution was made to the spring-cloud/spring-cloud-openfeignopen-source repository. The work involved understanding the existing codebase, identifying the underlying engineering problem, implementing a focused solution, and validating the change against the project's existing behaviour and testing standards.

Original Issue

Cache error handlers can execute multiple times when using @Cacheable with Feign clients.

The interaction between Spring Cache interception and Feign's caching invocation handling could cause cache interception and cache error handling to be applied more than once for a single Feign invocation.

Engineering Problem

Understanding the Problem

Feign clients using Spring's caching abstraction could pass through multiple caching interception paths. This could result in duplicate execution of cache error handlers and inconsistent behaviour when handling cache failures.

Solution

Implementation Approach

Added protection in FeignCachingInvocationHandlerFactory to guard against nested cache invocation and prevent the Feign caching layer from recursively invoking cache interception during the same request flow. The change also documents caching limitations and behaviour for Feign clients.

Technologies

Engineering Stack

JavaSpring BootSpring Cloud OpenFeignSpring CacheFeignThreadLocalDocumentation

Pull Request

View the Contribution

View the pull request and the associated engineering discussion directly on GitHub.

View Pull Request on GitHub →