fix(gcp): register nested URL protocol handler in GcfJarLauncher - #1434
fix(gcp): register nested URL protocol handler in GcfJarLauncher#1434akenra wants to merge 1 commit into
Conversation
099f18c to
8d82e93
Compare
yurbar
left a comment
There was a problem hiding this comment.
Unfortunately this doesn't fix Cloud Functions. Handlers.register() only sets java.protocol.handler.pkgs, but java.net.URL resolves the handler class via the bootstrap/system classloader, and the functions-framework loads the function jar in a child URLClassLoader — so nested.Handler is never visible. Reproduced on a real Boot 4.1.0 function jar: still unknown protocol: nested with the jar in a child loader; it only works with the jar on the system classpath, which is what the new test does (-cp classPath) — and the test never asserts GCF_JAR_LAUNCHER_SUCCEEDED, so it passes even when the launcher throws
Handlers.register() only sets java.protocol.handler.pkgs, which the JVM resolves through the bootstrap/system classloaders. The functions-framework loads the deployed function JAR in a child URLClassLoader, so nested.Handler inside the JAR is never visible there and URLs still fail with 'unknown protocol: nested'. Install a URLStreamHandlerFactory that provides the handler directly and rework the test to load the launcher from a fat JAR through a child classloader, asserting the launcher constructs successfully. Fixes spring-cloudgh-1336 Signed-off-by: akenra <37288280+akenra@users.noreply.github.com>
|
@yurbar thanks for the catch. I reworked the PR:
Could you re-check when you have a moment? Happy to adjust if the reproduction still doesn't match your setup. |
hi, @olegz!
I decided to try and fix this issue due to popular demand.
GcfJarLauncher's constructor bypasses Launcher.launch() and creates a LaunchedClassLoader directly, so it must register the nested: URL protocol handler itself. The tricky part is that the functions-framework does not load the function JAR on the system classpath - it loads it in a child URLClassLoader - and the JVM resolves java.protocol.handler.pkgs handlers only through the bootstrap/system classloaders. As a result, Handlers.register() alone still leaves the launcher with java.net.MalformedURLException: unknown protocol: nested (reproduced on a real Boot 4.1.0 function JAR, exactly as in gh-1336).
What I did:
Fixes gh-1336