-
Notifications
You must be signed in to change notification settings - Fork 890
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
[RESTEASY-2646]:Fix match cache in RootNode grows infinitely #2471
Conversation
resteasy-core/src/main/java/org/jboss/resteasy/core/registry/MatchCache.java
Outdated
Show resolved
Hide resolved
resteasy-core/src/main/java/org/jboss/resteasy/core/registry/RootNode.java
Outdated
Show resolved
Hide resolved
| @@ -56,10 +69,12 @@ public ResourceInvoker match(HttpRequest request, int start) | |||
| request.setAttribute(RESTEASY_CHOSEN_ACCEPT, match.chosen); | |||
| } else { | |||
| match = root.match(request, start); | |||
| if (match.match != null && match.match.expression.getNumGroups() == 0 && match.invoker instanceof ResourceMethodInvoker) { | |||
| if (cache.size() < CACHE_SIZE && match.match != null && match.match.expression.getNumGroups() == 0 && match.invoker instanceof ResourceMethodInvoker) { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So once the cache is full, nothing gets added / old entries removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ideal that we remove the LRU entry when the cache is full. Later we can look at ConcurrentLinkedHashMap which Ben suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just remember, that 99% of apps will only have a handful of media types (< 5), usually only 1 (json). Might be a little bigger if character sets are involved, but there's only a handful of those in existence as well. The issue here was a media type that adds a random parameter. IMO, if you hit the cache size you're dealing with an app that has another random parameter and the cache will be useless. Might as well clear it and turn it off in that scenario.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this per route? The cache size would be hit if an application has more than CACHE_SIZE routes, in the expected case.
The MediaTypeHeaderDelegate is a cache of media types and it clears itself when full. It doesn't condition for dynamic parameters, so a multipart route would invalidate it regularly.
|
@jimma Do you plan to include test case? |
|
@rsvoboda I didn't figure out how to write a test case for this issue. Do you have any idea ? |
|
@jimma nothing simple what could be added into the RESTEasy testsuite. |
|
You can do this: public class MyRootNode extends RootNode {
public int cacheSize() {
return cache.size();
}
}and run 2050x myRootNode.match(...) and check that myRootNode.cacheSize() returns 2048. |
resteasy-core/src/main/java/org/jboss/resteasy/core/registry/MatchCache.java
Outdated
Show resolved
Hide resolved
resteasy-core/src/main/java/org/jboss/resteasy/core/registry/MatchCache.java
Outdated
Show resolved
Hide resolved
|
As for managing overflow, LRU might be the appropriate strategy, but Bill's idea of just zapping the cache and starting over would have a similar effect.
|
|
I hate to mention this, but as of WF 20, the jaxrs module allows setting RESTEasy parameters. So ... technically ... we should update jaxrs. I HOPE that doesn't count as a Feature. |
|
@ronsigal WF is using 3.x series - https://github.com/wildfly/wildfly/blob/master/pom.xml#L392 |
|
I have prepared RootNodeCacheSizeTest rsvoboda@0406ac9 in my https://github.com/rsvoboda/Resteasy/tree/RootNodeCacheSizeTest branch If you like it, feel free to cherry pick it and include into this PR. |
|
As @rsvoboda commented, WildFly is not a concern atm, as this issue affects RESTEasy 4.x series only. |
+1. I already changed to clear cache when it's full and start over.
I'll add it to the documentation later. |
|
oops. Missed one commit change. Fixed. |
|
the issue number sems wrong. Is it for RESTEASY-2643 ? |
both are correct :) |
|
re: "WF is using 3.x series" D'oh!! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks ok to me now. Does anybody have strong concerns on moving on with this fix for now and possibly later enhance the solution with a proper caching mechanism / library integration?
/cc @patriot1burke
|
@asoldano, it's fine with me. I would also add documentation to the TODO list. |
|
Thank you for the prompt fix. Any timeline on when a release will be made? |
…y#2471) * [RESTEASY-2646]:Initial fix * [RESTEASY-2646]:More improvement * [RESTEASY-2646]:Get match catch config from system property * Code cleanup * [RESTEASY-2646]:Without caching match if the ContentType contains parameters * Test for RootNode cache size limit * Fix test Co-authored-by: Rostislav Svoboda <rsvoboda@redhat.com>
* [RESTEASY-2625]:Fix @produces(text/event-stream * [RESTEASY-2610] Upgrade MicroProfile REST Client to 1.4.1 * [RESTEASY-2595] Add getLinks method with a custom class loader * [RESTEASY-2597] add methods and test to support setting * [RESTEASY-2300] allow empty Host header for netty adapters * [RESTEASY-2300] test-cases for empty Host header field * Remove deps from the BOM that don't exist in the current version * [RESTEASY-2633] Encode code points that span multiple characters (#2456) Fixes RESTEASY-2633 * [RESTEASY-2637] Fix issue with Spring Web parameters encoding (#2453) Fixes: quarkusio/quarkus#10133 * Upgrade to wildfly 20.0.0.Final * Disable wiremock banner * [RESTEASY-2639] Bump version.log4j from 2.9.1 to 2.13.3 in /resteasy-dependencies-bom (#2460) Bumps `version.log4j` from 2.9.1 to 2.13.3. Updates `log4j-api` from 2.9.1 to 2.13.3 Updates `log4j-core` from 2.9.1 to 2.13.3 Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * [RESTEASY-2634] Fix HttpHeaders.getAcceptableLanguages (#2458) JAX-RS mandates that HttpHeaders.getAcceptableLanguages() returns a single wildcard locale instance if no acceptable languages are defined. * [RESTEASY-2642] Add doPrivs to sys prop checks (#2467) * [RESTEASY-2642] Add doPrivs to sys prop checks Signed-off-by: Andy McCright <j.andrew.mccright@gmail.com> * Review comment: only use doPriv if SecMgr is used Signed-off-by: Andy McCright <j.andrew.mccright@gmail.com> * [RESTEASY-2645] Upgrade Jackson to 2.11.1 * RESTEASY-2648 Upgrade json-patch to 1.13 * [RESTEASY-2648][RESTEASY-2327] Additional minor fix to modules and removal of exclusion * [RESTEASY-2649] Upgrade shrinkwrap to 2.2.7 (#2473) * [RESTEASY-2646]:Fix match cache in RootNode grows infinitely (#2471) * [RESTEASY-2646]:Initial fix * [RESTEASY-2646]:More improvement * [RESTEASY-2646]:Get match catch config from system property * Code cleanup * [RESTEASY-2646]:Without caching match if the ContentType contains parameters * Test for RootNode cache size limit * Fix test Co-authored-by: Rostislav Svoboda <rsvoboda@redhat.com> * Test for RESTEASY-2633 * [RESTEASY-2659] Performance improvements (#2479) - Avoid unnecessary use of URI.create - rather do more lazily - Multivalued maps will 99% of the time have 1 or maybe 2 entries for a key so don't allocate memory for 10 - Avoid unnecessary matcher creation when decoding when a string does not contain % in it - which is the more likely case for URI's to Rest resources These changes increase throughput by about 2% on a simple Rest service. Co-authored-by: Paul Carter-Brown <paul.carter-brown@jini.guru> * RESTEASY-2662 Don't create a context if it does not exist * [RESTEASY-2666] Upgrade httpclient/httpcore * [RESTEASY-2670] Ensure immutability and properly rely on builders * [RESTEASY-2669] Dealt with a few warnings * [RESTEASY-2668] Remove SseEventOutputProvider * [RESTEASY-2667] Removing SerializableProvider * [RESTEASY-2669] Misc cleanup and warning fixes * [RESTEASY-2669] Further warnings' cleanup in core * RESTEASY-2674 Escape sign of quotation to see the value of parameter * [RESTEASY-2661]:MediaTypeMap shared across threads, but cache is not … (#2498) * [RESTEASY-2661]:MediaTypeMap shared across threads, but cache is not thread-safe * Update MediaTypeMap.java Removing comment about volatility. Co-authored-by: Ron Sigal <rsigal@redhat.com> * [RESTEASY-2549] Remove resteasy-validator-provider source dependency on Hibernate Validate. [RESTEASY-2549] Moved NonCDIValidatorFactoryTest to integration-tests-embedded * Do not use ResteasyProviderFactory.getInstance() in SseEventProvider * [RESTEASY-2684] Statically set provider factory on ResteasyClientBuilderImpl (#2504) * [RESTEASY-2684] Statically set provider factory on ResteasyClientBuilderImpl * [RESTEASY-2684] Added unit test. * [RESTEASY-2684] Fix new unit test. Co-authored-by: Ron Sigal <rsigal@redhat.com> * [RESTEASY-2683] NPE in ApacheHttpClient43Test because cache is null in MediaTypeMap (#2501) * [RESTEASY-2592] removed profile forward.compatibility and annotation NotForForwardCompatibility * RESTEASY-2678 - Fix read priority from @priority with @RegisterProvider. * [RESTEASY-2687] Revisit fix in previous commit and remove ResteasyProviderFactory.getInstance() in other locations as well * Deprecated unused classes * [RESTEASY-2592] Restore unintentially disabled testsuites * Update target containers * [RESTEASY-2627] Chain thenCompose properly * [RESTEASY-2689] Fix SseEventOutputImpl wrong CompletionStage composition sequence * RESTEASY-2678 - Fix test. * [RESTEASY-2689]:Add a test case * [RESTEASY-2685] Merge client headers with MP REST Client * Add test to verify behavior * Needed to reset beanManager inside the extension for testing * Build to 4.5.7-SNAPSHOT Co-authored-by: Jim Ma <ema@redhat.com> Co-authored-by: Gytis Trikleris <gytis@redhat.com> Co-authored-by: R Searls <rsearls@redhat.com> Co-authored-by: Ivo Studensky <istudens@redhat.com> Co-authored-by: Alexey Loubyansky <olubyans@redhat.com> Co-authored-by: Stuart Douglas <stuart.w.douglas@gmail.com> Co-authored-by: Georgios Andrianakis <geoand@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Christoph Böhme <christoph@b3e.net> Co-authored-by: Andy McCright <j.andrew.mccright@gmail.com> Co-authored-by: George Gastaldi <gegastaldi@gmail.com> Co-authored-by: Tomaz Cerar <tomaz.cerar@gmail.com> Co-authored-by: Rostislav Svoboda <rsvoboda@redhat.com> Co-authored-by: bcluap <bcluap@gmail.com> Co-authored-by: Paul Carter-Brown <paul.carter-brown@jini.guru> Co-authored-by: Ron Sigal <rsigal@redhat.com> Co-authored-by: Ken Finnigan <ken@kenfinnigan.me> Co-authored-by: rmartinc <rmartinc@redhat.com> Co-authored-by: Roberto Cortez <radcortez@yahoo.com> Co-authored-by: a.koshkin <a.koshkin@tinkoff.ru>
* [RESTEASY-2646]:Initial fix * [RESTEASY-2646]:More improvement * [RESTEASY-2646]:Get match catch config from system property * Code cleanup * [RESTEASY-2646]:Without caching match if the ContentType contains parameters * Test for RootNode cache size limit * Fix test Co-authored-by: Rostislav Svoboda <rsvoboda@redhat.com>
No description provided.