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

Ensure client WebSocket connection can always be made #155

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import io.netty.channel.ChannelPipeline;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.nio.NioEventLoop;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.http.FullHttpRequest;
Expand Down Expand Up @@ -182,7 +184,8 @@ protected void verify(FullHttpResponse response) {
}
}, connectFunction);

b.group(eventLoopGroup)

b.group(determineEventLoopGroup())
.channel(NioSocketChannel.class)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
Expand Down Expand Up @@ -214,6 +217,15 @@ public void operationComplete(ChannelFuture future) throws Exception {
return handler.handshakeFuture;
}

// the bootstrap always uses NioSocketChannel, so we need to provide a proper NioEventLoopGroup
private EventLoopGroup determineEventLoopGroup() {
if (NioEventLoopGroup.class.equals(eventLoopGroup.getClass())) {
return eventLoopGroup;
}
// there is not much else we can do here...
return new NioEventLoopGroup();
Copy link
Member

Choose a reason for hiding this comment

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

I agree, but it's unfortunate. We should add a note in the Quarkus documentation when using the legacy web socket implementation; native transport is not recommended.

}


private class WebSocketClientHandler<R> extends SimpleChannelInboundHandler<Object> {

Expand Down
Loading