Repository navigation
Make shared runtime state immutable for v14 - #3677
Merged
Merged
Conversation
Signed-off-by: Marvin Froeder <velo.br@gmail.com>
Signed-off-by: Marvin Froeder <velo.br@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes the state that one Feign client shares across threads read-only once it is built. v14 is the release where breaking this API is acceptable.
MIGRATION-v14.mdgains an "Immutability" section with before/after examples.Changes
1. Built clients no longer share the builder's interceptor lists
SynchronousMethodHandler.Factory,AsynchronousMethodHandler.FactoryandMethodHandlerConfigurationnow copy the request and method interceptor lists withList.copyOf. Before,builder.requestInterceptor(...)called aftertarget(...)changed clients that were already built. It could also throwConcurrentModificationExceptionwhile requests were in flight.2.
Request.Optionsis a final value classsetMethodOptions/getMethodOptions. They stored per-method options in a map keyed by thread that was never cleared, so it grew without limit under thread pools and virtual threads. The options also only applied on the thread that set them. AnOptionsmethod parameter still overrides options for a single call.equals/hashCode/toString.Util.getThreadIdentifier().3.
Requestis immutableheaders()returns an unmodifiable map.Request.header(...). AddswithHeader(name, values), which returns a copy.requestTemplate()withmethodMetadata()andfeignTarget(), the only parts callers read. The template is created per call and can be changed, so it no longer leaks into clients, decoders and metrics. dropwizard-metrics4/5, micrometer and graphql are updated.Response.Builder.requestTemplate(...), which was never read.FeignContextswaps in a copy of its carrier for each propagated header.MicrometerObservationCapabilitynow sendsgetCarrier()in the sync path as well, so tracing headers still reach the wire;FeignHeaderInstrumentationTestchecks this.4.
MethodMetadatais read-only once parsedReflectiveFeigncalls a package-privatefreeze()after theContracthas parsed the interface. After that, setters throwIllegalStateExceptionand the collection getters return unmodifiable views. AContractstill builds metadata as before.Not included
MethodMetadata.template()still returns the shared, mutableRequestTemplate. Freezing it means guarding every method that changesRequestTemplate, or copying it on every call. That is left for a follow-up.RequestTemplatepipeline. It would change theEncoder,RequestInterceptorandContractsignatures in about 125 files, with no thread-safety gain, because a template is created per call.Tests
ImmutabilityTest: builder changes after build, frozen metadata.RequestTest: headers are copied, andwithHeaderkeeps case-insensitive lookup.OptionsTest: removed the subclass tests and the thread-map tests, added a value-equality test.mvn installpasses. The only failures areform-springandGitHubExampleIT, and both fail on14.xwithout this change.