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

Undertow - Only load resources that are known #43694

Merged
merged 3 commits into from
Oct 14, 2024

Conversation

gsmet
Copy link
Member

@gsmet gsmet commented Oct 4, 2024

If we try to load every resource, we end up creating cache entries in the resourceCache CHM of the AppClassLoader, which is definitely not what we want in this case, given we are supposed to serve only known resources.

Now I must admit the fix looks a bit too simple to be true :).

Fixes #43676

@gsmet
Copy link
Member Author

gsmet commented Oct 4, 2024

@stuartwdouglas in case you have one minute to check if what I did is right or completely wrong, that would be appreciated. It looks like an oversight but you might have had very good reasons to not do that.

Interesting context is here: #43676 (comment) .

@gsmet
Copy link
Member Author

gsmet commented Oct 4, 2024

OK, well, it doesn't look very good:

2024-10-04 11:25:20,035 ERROR [io.und.req.io] (executor-thread-1) Exception handling request b5951dd0-02d8-495a-8b76-5fcadb031235-1 to /foo/bar: java.lang.NullPointerException: Cannot invoke "java.util.Set.stream()" because "paths" is null
	at io.quarkus.undertow.test.ResourceManagerTestCase$ContextPathServlet.doGet(ResourceManagerTestCase.java:55)
	at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:527)
	at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:614)
	at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
	at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:63)
	at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
	at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
	at io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:67)
	at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:133)

I will have a second look after Devoxx.

This comment has been minimized.

@gsmet gsmet marked this pull request as draft October 10, 2024 17:29
@gsmet
Copy link
Member Author

gsmet commented Oct 10, 2024

I pushed an additional commit (to be dropped) to get more information about the Windows CI failure.

@gsmet
Copy link
Member Author

gsmet commented Oct 10, 2024

I had a closer look and we were actually collecting incorrect paths on Windows since forever but the previous code was actually fine with it. Now that we are stricter, we need to make sure the paths are correct.

@gsmet gsmet force-pushed the undertow-load-known branch 2 times, most recently from 79c7818 to ebb961b Compare October 11, 2024 07:08
@gsmet gsmet marked this pull request as ready for review October 11, 2024 07:13

This comment has been minimized.

@gsmet
Copy link
Member Author

gsmet commented Oct 11, 2024

This should be ready now. We were doing shady things on Windows. I cleaned up things by making sure the paths are normalized from the start, instead of doing it on an ad hoc basis.

If we try to load every resource, we end up creating cache entries in
the resourceCache CHM of the AppClassLoader, which is definitely not
what we want in this case, given we are supposed to serve only known
resources.

Fixes quarkusio#43676
Copy link

quarkus-bot bot commented Oct 11, 2024

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit 8d5680a.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

You can consult the Develocity build scans.

@melloware
Copy link
Contributor

@gsmet i think I helped cause some of this mess while trying to fix #28028 and created a test case with #33018

@prateeksharma2988
Copy link

prateeksharma2988 commented Oct 14, 2024

@gsmet Just for our reference, in which release version of quarkus, we should expect this fix would be available.
will it be available in 3.15 and 3.8 as LTS version update ?

@gsmet
Copy link
Member Author

gsmet commented Oct 14, 2024

@prateeksharma2988 TBH the patch is a lot more involved than I thought it would be so I'm still unsure if we should backport it. It might get backported to 3.15 but I don't think it will hit 3.8.

Also we will need some bake time once 3.16 is released before we even think about backporting it.

Comment on lines +69 to +71
if (!files.contains(path)) {
return null;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is actually here. The rest is to make paths consistent so that we don't end up comparing Unix-styled paths and Windows-style paths.

@gsmet
Copy link
Member Author

gsmet commented Oct 14, 2024

@geoand @gastaldi I would appreciate another look at this one to make sure it makes sense.

The rationale of the patch is that in prod mode, we know which files are around and we have a fixed list of them and so we shouldn't try to resolve them from the class loader as we will end up caching all the negative hits, which might cause the CL to become huge if you have a lot of invalid requests.

I think that it was the original intent and that it somehow got lost.

@geoand
Copy link
Contributor

geoand commented Oct 14, 2024

I will take a look tomorrow

Copy link
Contributor

@gastaldi gastaldi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@geoand geoand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed looks like a legit omission :)

@gsmet gsmet merged commit 46f6063 into quarkusio:main Oct 14, 2024
48 checks passed
@quarkus-bot quarkus-bot bot added this to the 3.16 - main milestone Oct 14, 2024
@melloware
Copy link
Contributor

Can one of you kick off this build: #33018 I just rebased and want to see if it fixes that test case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Undertow CacheResourceManager can cause frequent GC
5 participants