-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Async
-
None
-
(copied to CRM)
-
None
-
Java Drivers
-
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()))