Skip to content

Commit b952e41

Browse files
committed
Netty fixes
Update Netty to 4.1.5.final Fix leak in NettyStream Made connection string streamType the authorative setting for the streamFactoryFactory Added deprecation warning in NettyByteBuf JAVA-2302
1 parent 2c117b6 commit b952e41

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ apply plugin: 'eclipse'
1818
apply plugin: 'idea'
1919

2020
def configDir = new File(rootDir, 'config')
21-
ext.nettyVersion = '4.0.26.Final'
21+
ext.nettyVersion = '4.1.5.Final'
2222

2323
buildscript {
2424
repositories {

driver-async/src/main/com/mongodb/async/client/MongoClients.java

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.mongodb.client.MongoDriverInformation;
2121
import com.mongodb.client.gridfs.codecs.GridFSFileCodecProvider;
2222
import com.mongodb.client.model.geojson.codecs.GeoJsonCodecProvider;
23+
import com.mongodb.connection.AsynchronousSocketChannelStreamFactoryFactory;
2324
import com.mongodb.connection.Cluster;
2425
import com.mongodb.connection.ClusterSettings;
2526
import com.mongodb.connection.ConnectionPoolSettings;
@@ -155,6 +156,8 @@ public static MongoClient create(final ConnectionString connectionString, final
155156
if (connectionString.getStreamType() != null) {
156157
if (connectionString.getStreamType().toLowerCase().equals("netty")) {
157158
builder.streamFactoryFactory(NettyStreamFactoryFactory.builder().build());
159+
} else if (connectionString.getStreamType().toLowerCase().equals("nio2")) {
160+
builder.streamFactoryFactory(new AsynchronousSocketChannelStreamFactoryFactory());
158161
} else if (!connectionString.getStreamType().toLowerCase().equals("nio2")) {
159162
throw new IllegalArgumentException(format("Unsupported stream type %s", connectionString.getStreamType()));
160163
}

driver-async/src/test/functional/com/mongodb/async/client/MongoClientsSpecification.groovy

+24
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,30 @@ class MongoClientsSpecification extends FunctionalSpecification {
198198
'mongodb://localhost/?appname=app1' | 'app1'
199199
}
200200

201+
@Unroll
202+
def 'should respect the streamType over the system properties'() {
203+
given:
204+
def asyncType = System.getProperty('org.mongodb.async.type', null)
205+
System.setProperty('org.mongodb.async.type', systemType)
206+
207+
when:
208+
def client = MongoClients.create(uri)
209+
210+
then:
211+
client.settings.getStreamFactoryFactory().getClass() == streamFactoryFactoryClass
212+
213+
cleanup:
214+
client?.close()
215+
if (asyncType != null) {
216+
System.setProperty('org.mongodb.async.type', asyncType)
217+
}
218+
219+
where:
220+
uri | systemType | streamFactoryFactoryClass
221+
'mongodb://localhost/?streamType=nio2' | 'netty' | AsynchronousSocketChannelStreamFactoryFactory
222+
'mongodb://localhost/?streamType=netty' | 'nio2' | NettyStreamFactoryFactory
223+
}
224+
201225
@IgnoreIf({ !serverVersionAtLeast([3, 3, 9]) || !isStandalone() })
202226
def 'application name should appear in the system.profile collection'() {
203227
given:

driver-core/src/main/com/mongodb/connection/netty/NettyByteBuf.java

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public ByteBuf clear() {
113113
}
114114

115115
@Override
116+
@SuppressWarnings("deprecation")
116117
public ByteBuf order(final ByteOrder byteOrder) {
117118
proxied = proxied.order(byteOrder);
118119
return this;

driver-core/src/main/com/mongodb/connection/netty/NettyStream.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,7 @@ public ByteBuf read(final int numBytes) throws IOException {
171171
public void writeAsync(final List<ByteBuf> buffers, final AsyncCompletionHandler<Void> handler) {
172172
CompositeByteBuf composite = PooledByteBufAllocator.DEFAULT.compositeBuffer();
173173
for (ByteBuf cur : buffers) {
174-
io.netty.buffer.ByteBuf byteBuf = ((NettyByteBuf) cur).asByteBuf();
175-
composite.addComponent(byteBuf.retain());
176-
composite.writerIndex(composite.writerIndex() + byteBuf.writerIndex());
174+
composite.addComponent(true, ((NettyByteBuf) cur).asByteBuf());
177175
}
178176

179177
channel.writeAndFlush(composite).addListener(new ChannelFutureListener() {

0 commit comments

Comments
 (0)