NettyStreamFactory IllegalReferenceCountException

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • 5.6.2
    • Affects Version/s: None
    • Component/s: Async
    • None
    • 🔵 Done
    • Fully Compatible
    • Java Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      This test https://github.com/mongodb/mongo-java-driver/blob/main/driver-core/src/test/functional/com/mongodb/internal/connection/CommandHelperSpecification.groovy#L46 will fail when registering a logger

      def setup() {
         InternalStreamConnection.setRecordEverything(true)
         connection = new InternalStreamConnectionFactory(ClusterConnectionMode.SINGLE,
                      new NettyStreamFactory(SocketSettings.builder().build(), getSslSettings()),
                      getCredentialWithCache(), CLIENT_METADATA, [], LoggerSettings.builder().build(), null, getServerApi())
                      .create(new ServerId(new ClusterId(), getPrimary()))
              connection.open(OPERATION_CONTEXT)
      

      it throws

      io.netty.util.IllegalReferenceCountException
      com.mongodb.MongoException: io.netty.util.IllegalReferenceCountException
      	at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:266)
      	at com.mongodb.internal.connection.CommandHelperSpecification.setup(CommandHelperSpecification.groovy:51)
      Caused by: io.netty.util.IllegalReferenceCountException
      	at io.netty.buffer.AbstractPooledDerivedByteBuf.unwrap(AbstractPooledDerivedByteBuf.java:57)
      	at io.netty.buffer.PooledDuplicatedByteBuf.getInt(PooledDuplicatedByteBuf.java:159)
      	at io.netty.buffer.SwappedByteBuf.getInt(SwappedByteBuf.java:284)
      	at com.mongodb.internal.connection.netty.NettyByteBuf.getInt(NettyByteBuf.java:230)
      	at com.mongodb.internal.connection.CompositeByteBuf.getInt(CompositeByteBuf.java:200)
      	at com.mongodb.internal.connection.CompositeByteBuf.getInt(CompositeByteBuf.java:192)
      	at org.bson.io.ByteBufferBsonInput.readInt32(ByteBufferBsonInput.java:112)
      	at org.bson.BsonBinaryReader.readSize(BsonBinaryReader.java:380)
      	at org.bson.BsonBinaryReader.doReadStartDocument(BsonBinaryReader.java:274)
      	at org.bson.AbstractBsonReader.readStartDocument(AbstractBsonReader.java:450)
      	at com.mongodb.internal.connection.ByteBufBsonDocument.findInDocument(ByteBufBsonDocument.java:119)
      	at com.mongodb.internal.connection.ByteBufBsonDocument.getFirstKey(ByteBufBsonDocument.java:296)
      	at com.mongodb.internal.connection.InternalStreamConnection.createTracingSpan(InternalStreamConnection.java:1054)
      	at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceiveInternal(InternalStreamConnection.java:459)
      	at com.mongodb.internal.connection.InternalStreamConnection.lambda$sendAndReceive$0(InternalStreamConnection.java:396)
      	at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:399)
      	at com.mongodb.internal.connection.CommandHelper.sendAndReceive(CommandHelper.java:100)
      	at com.mongodb.internal.connection.CommandHelper.executeCommand(CommandHelper.java:49)
      	at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:144)
      	at com.mongodb.internal.connection.InternalStreamConnectionInitializer.startHandshake(InternalStreamConnectionInitializer.java:78)
      	at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:256)
      
      

      This was discovered when trying to get the command name (for Micrometer) using

      message.getCommandDocument(bsonOutput)
      

      However, this is independent of Micrometre since the same failure will happen if we register a LoggingCommandEventSender

      Note: using SocketStreamFactory will work

      // works
      connection = new InternalStreamConnectionFactory(ClusterConnectionMode.SINGLE,
                      new SocketStreamFactory(new DefaultInetAddressResolver(), SocketSettings.builder().build(), getSslSettings()),
                      getCredentialWithCache(), CLIENT_METADATA, [], LoggerSettings.builder().build(), null, getServerApi())
                      .create(new ServerId(new ClusterId(), getPrimary()))
      

            Assignee:
            Ross Lawley
            Reporter:
            Nabil Hachicha
            Valentin Kavalenka
            Votes:
            2 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: