micronaut-projects / micronaut-core

Micronaut Application Framework
http://micronaut.io
Apache License 2.0
6.04k stars 1.06k forks source link

Upgrading to micronaut 4.x - issues with HTTP and ALPN #10440

Open Piotreqsl opened 7 months ago

Piotreqsl commented 7 months ago

Issue description

I have a question regarding HTTP and ALPN changes introduced in 4.x version.

Problem description: I've got application that uses WebSocket to connect to some external server. After upgrade to version 4.2.3 (from 3.9.0) I had a very strange connectivity problem - connection ended instantly with 1006:AbnormalClosure close code.

I've tried to debug it using Wireshark (because there were no more errors in micronaut) and i saw ConnectionResets and some Cipher Problems.

Solution was to explicitly set Client HTTP version to 1.1 (because that external server doesn't support HTTP2). It was pretty unclear to me, because the docs says that default version of HTTP is 1.1. Later on I found a change in Client interface (annotation), that was introduced in 4.0.0, that enables by default ALPN from HTTP2:

     * @since 4.0.0
     */
    @NonNull
    String[] alpnModes() default {
        HttpVersionSelection.ALPN_HTTP_2,
        HttpVersionSelection.ALPN_HTTP_1
    };

Changing ALPNModes in annotation to HTTP_1 has also fixed my problem, because it excluded HTTP2 ALPN Modes.

So now here is the question: Was this change documented somewhere in docs? Because I've tried to search in micronaut upgrade reference and other docs and I've not found mention of it. Or maybe is it possible to give more verbose error logs to connection problems? (I've tried setting netty log-level to debug and trace and it didn't help too.)

yawkat commented 7 months ago

your intervention is only necessary because the server signals support for http2 through alpn but the support is broken (the 1006 you see). For normal working servers this should not be a problem

Piotreqsl commented 7 months ago

Could you please provide more description why that's happening? It's because that server has some outdated dependencies or something? Also, shouldn't release notes/documentation include info potential issues related to ALPN changes?

yawkat commented 7 months ago

i dont know why the server is sending 1006.

the alpn change does not get a special callout in the release notes because it is not a breaking change. http1-only conversations still work, that's being negotiated by alpn. your case only doesnt work because http2 is broken (not just unsupported).

Piotreqsl commented 7 months ago

Maybe a note that now protocols are being negotiated using alpn and servers that they don't support won't be able to negotiate 1.1?

waynerijsdijk commented 7 months ago

I have the exact same problem after upgrading from Micronaut 3.8.9 to Micronaut 4.2.3. Setting the ALPN-mode to HTTP1/1 solves the problem indeed.

My websocket server application is created with Micronaut and runs on GCP Cloud run. The websocket client application is also created with Micronaut and also runs on GCP Cloud run.