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

MicrometerCapability is applied multiple times when using a Feign.Builder to build multiple Feign instances #1961

Closed
lbilger opened this issue Feb 27, 2023 · 4 comments · Fixed by #2117
Labels
bug Unexpected or incorrect behavior feedback provided Feedback has been provided to the author

Comments

@lbilger
Copy link

lbilger commented Feb 27, 2023

Each time Feign.Builder.build() is used to build a new Feign instance, it calls enrich to apply the Capabilitys. The MicrometerCapability then wraps the Client, Encoder, Decoder etc. in MeteredXxx decorators. So with each time I build a new Feign from the same Builder, the decorator chain grows by one, so I get e.g a MeteredDecoder wrapped in a MeteredDecoder wrapped in a MeteredDecoder and so on. In our case, this caused a StackOverflowError after the application ran for a while.

Suggestion: Check if the Decoder is already an instance of MeteredDecoder and skip wrapping if it is. (Same for the other objects as well, of course.) But beware: This will not help if you have two capabilities that decorate these objects, because then one capability might only see the decorator from the other capability, not its own...

Other option: Change the code in Feign.Builder to apply the capabilities only once.

@vitalijr2
Copy link
Collaborator

vitalijr2 commented Feb 27, 2023

There are two options:

  1. we do not change builder after call of builder()
  2. we add another logger, decoder or make another change

We can skip enrich() for option 1 but we must call it for option 2 (of course we can make double wrap for some fields that was wrapped earlier.

I propose another way: just clone builder and then call builder() of this clone but never call it for the master.

@lbilger
Copy link
Author

lbilger commented Feb 27, 2023

Thanks @radio-rogal, you are of course right, both my suggestions are flawed. Thinking about it some more, it occurs to me that the Capability mechanism should not modify the builder at all. Instead, the builder could feed the results of enriching directly into the objects it creates when the build() method is called. What do you think?

@kdavisk6 kdavisk6 added proposal Proposed Specification or API change feedback provided Feedback has been provided to the author bug Unexpected or incorrect behavior and removed proposal Proposed Specification or API change labels May 24, 2023
@vitalijr2
Copy link
Collaborator

@lbilger could you review changes #2117 (and maybe test them) ?

@lbilger
Copy link
Author

lbilger commented Jul 17, 2023

@radio-rogal sorry for the late reply, I tested it now and it looks good to me. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected or incorrect behavior feedback provided Feedback has been provided to the author
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants