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

12.1.0 - ResourceHandler is unable to serve content from PathResource that doesn't support mapped file buffers. #12695

Open
joakime opened this issue Jan 9, 2025 · 1 comment · May be fixed by #12696
Assignees
Labels
Bug For general bugs on Jetty side

Comments

@joakime
Copy link
Contributor

joakime commented Jan 9, 2025

Jetty version(s)
12.1.0.alpha1

Jetty Environment
core

Java version/vendor (use: java -version)

openjdk 17.0.11 2024-04-16
OpenJDK Runtime Environment Temurin-17.0.11+9 (build 17.0.11+9)
OpenJDK 64-Bit Server VM Temurin-17.0.11+9 (build 17.0.11+9, mixed mode, sharing)

OS type/version
Linux / Ubuntu

Description
If you have a Resource Base that is a PathResource that points to a FS that doesn't support file mapping, like zipfs, then you are unable to serve files from ResourceHandler.

This works in 12.0.16 just fine.

2025-01-09 13:43:22.809:WARN :oejs.Response:qtp2008106788-169: writeError: status=500, message=java.lang.UnsupportedOperationException, response=ErrorResponse@1e15b2b8{500,GET@2e2db70a http://192.168.1.221:40715/jars/webjars/bootstrap/5.3.3/js/bootstrap.bundle.js HTTP/1.1}
java.lang.UnsupportedOperationException
	at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem$1.map(ZipFileSystem.java:1102)
	at org.eclipse.jetty.util.BufferUtil.toMappedBuffer(BufferUtil.java:1178)
	at org.eclipse.jetty.util.BufferUtil.toMappedBuffer(BufferUtil.java:1171)
	at org.eclipse.jetty.http.content.FileMappingHttpContentFactory$SingleBufferFileMappedHttpContent.<init>(FileMappingHttpContentFactory.java:103)
	at org.eclipse.jetty.http.content.FileMappingHttpContentFactory.getContent(FileMappingHttpContentFactory.java:78)
	at org.eclipse.jetty.http.content.VirtualHttpContentFactory.getContent(VirtualHttpContentFactory.java:60)
	at org.eclipse.jetty.http.content.PreCompressedHttpContentFactory.getContent(PreCompressedHttpContentFactory.java:48)
	at org.eclipse.jetty.http.content.CachingHttpContentFactory.getContent(CachingHttpContentFactory.java:229)
	at org.eclipse.jetty.server.ResourceService.getContent(ResourceService.java:88)
	at org.eclipse.jetty.server.handler.ResourceHandler.handle(ResourceHandler.java:174)
	at org.eclipse.jetty.server.Handler$Wrapper.handle(Handler.java:740)
	at examples.PathMappingServer$PathNameWrapper.handle(PathMappingServer.java:177)
	at org.eclipse.jetty.server.handler.PathMappingsHandler.handle(PathMappingsHandler.java:116)
	at org.eclipse.jetty.server.Server.handle(Server.java:182)
	at org.eclipse.jetty.server.internal.HttpChannelState$HandlerInvoker.run(HttpChannelState.java:672)
	at org.eclipse.jetty.server.internal.HttpConnection.onFillable(HttpConnection.java:411)
	at org.eclipse.jetty.server.internal.HttpConnection$FillableCallback.succeeded(HttpConnection.java:1688)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:99)
	at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:979)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.doRunJob(QueuedThreadPool.java:1209)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1164)
	at java.base/java.lang.Thread.run(Thread.java:840)

I think the toMappedBuffer should catch UnsupportedOperationException and fallback to non-mapped option.

@joakime joakime added the Bug For general bugs on Jetty side label Jan 9, 2025
@joakime
Copy link
Contributor Author

joakime commented Jan 9, 2025

The issue isn't zipfs specific, it's just the easiest way to trigger this UnsupportedOperationException.

See https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/channels/FileChannel.html#map(java.nio.channels.FileChannel.MapMode,long,long)

We should also consider if a file is too small for memory mapping, per the recommendations in the javadoc linked above.

"For most operating systems, mapping a file into memory is more expensive than reading or writing a few tens of kilobytes of data via the usual read and write methods. From the standpoint of performance it is generally only worth mapping relatively large files into memory."

@joakime joakime assigned joakime and unassigned lorban Jan 9, 2025
@joakime joakime moved this to 🏗 In progress in Jetty 12.1.0 Jan 9, 2025
joakime added a commit that referenced this issue Jan 9, 2025
joakime added a commit that referenced this issue Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For general bugs on Jetty side
Projects
Status: 🏗 In progress
2 participants