vert-x3 / vertx-tcp-eventbus-bridge

Apache License 2.0
49 stars 44 forks source link

Unregistering a consumer fails #34

Closed PhilLehmann closed 6 years ago

PhilLehmann commented 6 years ago

Version

Context

While unregistering a consumer, vertx-eventbus-bridge-clients fails:

Unhandled exception java.lang.IllegalArgumentException: Invalid frame type unregister at io.vertx.ext.eventbus.bridge.tcp.impl.TcpEventBusBridgeImpl.parseType(TcpEventBusBridgeImpl.java:409) at io.vertx.ext.eventbus.bridge.tcp.impl.TcpEventBusBridgeImpl.lambda$handler$8(TcpEventBusBridgeImpl.java:252) at io.vertx.ext.eventbus.bridge.tcp.impl.protocol.FrameParser.handle(FrameParser.java:67) at io.vertx.ext.eventbus.bridge.tcp.impl.protocol.FrameParser.handle(FrameParser.java:30) at io.vertx.core.net.impl.NetSocketImpl$DataMessageHandler.handle(NetSocketImpl.java:384) at io.vertx.core.net.impl.NetSocketImpl.handleMessageReceived(NetSocketImpl.java:351) at io.vertx.core.net.impl.NetServerImpl$2.handleMessage(NetServerImpl.java:446) at io.vertx.core.net.impl.NetServerImpl$2.handleMessage(NetServerImpl.java:443) at io.vertx.core.net.impl.VertxHandler.lambda$channelRead$1(VertxHandler.java:146) at io.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:337) at io.vertx.core.impl.ContextImpl.executeFromIO(ContextImpl.java:195) at io.vertx.core.net.impl.VertxHandler.channelRead(VertxHandler.java:144) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1359) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:935) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:134) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) at java.lang.Thread.run(Thread.java:745)

Extra

In 3.4.2, a PING message was detected with

https://github.com/philrykoff/vertx-tcp-eventbus-bridge/blob/3.4.2/src/main/java/io/vertx/ext/eventbus/bridge/tcp/impl/TcpEventBusBridgeImpl.java

      final String type = msg.getString("type", "message");

      if ("ping".equals(type)) {
        // discard
        return;
      }

In the current version, the method parseType has been added for detecting PING messages. But it currently only allows for four message types:

  private static BridgeEventType parseType(String typeStr) {
    switch (typeStr) {
      case "ping":
        return BridgeEventType.SOCKET_PING;
      case "register":
        return BridgeEventType.REGISTER;
      case "publish":
        return BridgeEventType.PUBLISH;
      case "send":
        return BridgeEventType.SEND;
      default:
        throw new IllegalArgumentException("Invalid frame type " + typeStr);
    }
  }

We have two options:

I would make this dependant on whether you would like to use parseType anywhere else in this project. If it will just be used for pings, I would fall back.

Opinions?

vietj commented 6 years ago

it seems weird that unregister is not listed in the protocol : https://github.com/vert-x3/vertx-tcp-eventbus-bridge

vietj commented 6 years ago

@pmlopes why don't we have an unregister frame in the protocol ?

PhilLehmann commented 6 years ago

It's listed below "Messages from the client -> bridge".

vietj commented 6 years ago

ah right I only see "register" and did not read the second one.

the first issue is that behavior is not tested in the tests of this project.

vietj commented 6 years ago

then I think we should simple add an "unregister" case in the switch statement and handle it properly

PhilLehmann commented 6 years ago

Makes sense. I'll PR.

vietj commented 6 years ago

great!

PhilLehmann commented 6 years ago

Could you merge the existing PR and put the regression test up for grabs for someone who already wrote tests for this project? We could leave this issue open.

vietj commented 6 years ago

where is the regression test @philrykoff ?

PhilLehmann commented 6 years ago

That's why I asked to put it up for grabs... the test framework is different from eventbus-clients, e.g. Thread.sleep throws exceptions. I'd like for someone else to add a test.

vietj commented 6 years ago

ok

andreas-eberle commented 6 years ago

Looks like this is fixed with #39, isn't it?

PhilLehmann commented 6 years ago

Indeed, thanks!