Skip to content

Commit 6a7067b

Browse files
authored
Merge pull request #32 from SpigotMC/master
[pull] master from SpigotMC:master
2 parents abf73c9 + d7538df commit 6a7067b

File tree

6 files changed

+40
-41
lines changed

6 files changed

+40
-41
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
<dependency>
8181
<groupId>io.netty</groupId>
8282
<artifactId>netty-bom</artifactId>
83-
<version>4.1.119.Final</version>
83+
<version>4.2.0.Final</version>
8484
<type>pom</type>
8585
<scope>import</scope>
8686
</dependency>

proxy/pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@
5151
<scope>compile</scope>
5252
</dependency>
5353
<dependency>
54-
<groupId>io.netty.incubator</groupId>
55-
<artifactId>netty-incubator-transport-native-io_uring</artifactId>
56-
<version>0.0.25.Final</version>
54+
<groupId>io.netty</groupId>
55+
<artifactId>netty-transport-native-io_uring</artifactId>
5756
<classifier>linux-x86_64</classifier>
57+
<scope>compile</scope>
5858
</dependency>
5959
<dependency>
60-
<groupId>io.netty.incubator</groupId>
61-
<artifactId>netty-incubator-transport-native-io_uring</artifactId>
62-
<version>0.0.25.Final</version>
60+
<groupId>io.netty</groupId>
61+
<artifactId>netty-transport-native-io_uring</artifactId>
6362
<classifier>linux-aarch_64</classifier>
63+
<scope>compile</scope>
6464
</dependency>
6565
<dependency>
6666
<groupId>net.md-5</groupId>

proxy/src/main/java/net/md_5/bungee/UserConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ public void connect(final ServerConnectRequest request)
334334
{
335335
Preconditions.checkNotNull( request, "request" );
336336

337-
ch.getHandle().eventLoop().execute( () -> connect0( request ) );
337+
ch.scheduleIfNecessary( () -> connect0( request ) );
338338
}
339339

340340
private void connect0(final ServerConnectRequest request)

proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.google.common.base.Preconditions;
44
import com.google.gson.Gson;
5-
import io.netty.channel.EventLoop;
65
import java.math.BigInteger;
76
import java.net.InetSocketAddress;
87
import java.net.SocketAddress;
@@ -284,6 +283,7 @@ private ServerPing getPingInfo(String motd, int protocol)
284283
public void handle(StatusRequest statusRequest) throws Exception
285284
{
286285
Preconditions.checkState( thisState == State.STATUS, "Not expecting STATUS" );
286+
thisState = null; // don't accept multiple status requests and set state to ping in async event callback
287287

288288
ServerInfo forced = AbstractReconnectHandler.getForcedHost( this );
289289
final String motd = ( forced != null ) ? forced.getMotd() : listener.getMotd();
@@ -307,10 +307,7 @@ public void done(ProxyPingEvent pingResult, Throwable error)
307307
{
308308
Gson gson = PingHandler.gson;
309309
unsafe.sendPacket( new StatusResponse( gson.toJson( pingResult.getResponse() ) ) );
310-
if ( bungee.getConnectionThrottle() != null )
311-
{
312-
bungee.getConnectionThrottle().unthrottle( getSocketAddress() );
313-
}
310+
thisState = State.PING;
314311
}
315312
};
316313

@@ -325,8 +322,6 @@ public void done(ProxyPingEvent pingResult, Throwable error)
325322
{
326323
pingBack.done( getPingInfo( motd, protocol ), null );
327324
}
328-
329-
thisState = State.PING;
330325
}
331326

332327
@Override
@@ -335,6 +330,10 @@ public void handle(PingPacket ping) throws Exception
335330
Preconditions.checkState( thisState == State.PING, "Not expecting PING" );
336331
unsafe.sendPacket( ping );
337332
disconnect( "" );
333+
if ( bungee.getConnectionThrottle() != null )
334+
{
335+
bungee.getConnectionThrottle().unthrottle( getSocketAddress() );
336+
}
338337
}
339338

340339
@Override
@@ -901,17 +900,7 @@ private <T> Callback<T> eventLoopCallback(Callback<T> callback)
901900
{
902901
return (result, error) ->
903902
{
904-
EventLoop eventLoop = ch.getHandle().eventLoop();
905-
if ( eventLoop.inEventLoop() )
906-
{
907-
if ( !ch.isClosing() )
908-
{
909-
callback.done( result, error );
910-
}
911-
return;
912-
}
913-
914-
eventLoop.execute( () ->
903+
ch.scheduleIfNecessary( () ->
915904
{
916905
if ( !ch.isClosing() )
917906
{

proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ public void scheduleIfNecessary(Runnable task)
238238
return;
239239
}
240240

241-
ch.eventLoop().execute( task );
241+
ch.eventLoop().submit( task ).addListener( future ->
242+
{
243+
if ( !future.isSuccess() )
244+
{
245+
ch.pipeline().fireExceptionCaught( future.cause() );
246+
}
247+
} );
242248
}
243249
}

proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,30 @@
66
import io.netty.channel.ChannelException;
77
import io.netty.channel.ChannelOption;
88
import io.netty.channel.EventLoopGroup;
9+
import io.netty.channel.MultiThreadIoEventLoopGroup;
910
import io.netty.channel.ServerChannel;
1011
import io.netty.channel.WriteBufferWaterMark;
1112
import io.netty.channel.epoll.Epoll;
1213
import io.netty.channel.epoll.EpollDatagramChannel;
1314
import io.netty.channel.epoll.EpollDomainSocketChannel;
14-
import io.netty.channel.epoll.EpollEventLoopGroup;
15+
import io.netty.channel.epoll.EpollIoHandler;
1516
import io.netty.channel.epoll.EpollServerDomainSocketChannel;
1617
import io.netty.channel.epoll.EpollServerSocketChannel;
1718
import io.netty.channel.epoll.EpollSocketChannel;
18-
import io.netty.channel.nio.NioEventLoopGroup;
19+
import io.netty.channel.nio.NioIoHandler;
1920
import io.netty.channel.socket.DatagramChannel;
2021
import io.netty.channel.socket.nio.NioDatagramChannel;
2122
import io.netty.channel.socket.nio.NioServerSocketChannel;
2223
import io.netty.channel.socket.nio.NioSocketChannel;
2324
import io.netty.channel.unix.DomainSocketAddress;
25+
import io.netty.channel.uring.IoUring;
26+
import io.netty.channel.uring.IoUringDatagramChannel;
27+
import io.netty.channel.uring.IoUringIoHandler;
28+
import io.netty.channel.uring.IoUringServerSocketChannel;
29+
import io.netty.channel.uring.IoUringSocketChannel;
2430
import io.netty.handler.codec.haproxy.HAProxyMessageDecoder;
2531
import io.netty.handler.timeout.ReadTimeoutHandler;
2632
import io.netty.handler.timeout.WriteTimeoutHandler;
27-
import io.netty.incubator.channel.uring.IOUring;
28-
import io.netty.incubator.channel.uring.IOUringDatagramChannel;
29-
import io.netty.incubator.channel.uring.IOUringEventLoopGroup;
30-
import io.netty.incubator.channel.uring.IOUringServerSocketChannel;
31-
import io.netty.incubator.channel.uring.IOUringSocketChannel;
3233
import io.netty.util.AttributeKey;
3334
import io.netty.util.internal.PlatformDependent;
3435
import java.net.SocketAddress;
@@ -133,16 +134,17 @@ private static void setChannelInitializerHolders()
133134
{
134135
if ( !PlatformDependent.isWindows() )
135136
{
136-
// disable by default (experimental)
137+
// disable by default
138+
// TODO: maybe make it the new default?
137139
if ( Boolean.parseBoolean( System.getProperty( "bungee.io_uring", "false" ) ) )
138140
{
139141
ProxyServer.getInstance().getLogger().info( "Not on Windows, attempting to use enhanced IOUringEventLoopGroup" );
140-
if ( io_uring = IOUring.isAvailable() )
142+
if ( io_uring = IoUring.isAvailable() )
141143
{
142144
ProxyServer.getInstance().getLogger().log( Level.WARNING, "io_uring is enabled and working, utilising it! (experimental feature)" );
143145
} else
144146
{
145-
ProxyServer.getInstance().getLogger().log( Level.WARNING, "io_uring is not working: {0}", Util.exception( IOUring.unavailabilityCause() ) );
147+
ProxyServer.getInstance().getLogger().log( Level.WARNING, "io_uring is not working: {0}", Util.exception( IoUring.unavailabilityCause() ) );
146148
}
147149
}
148150

@@ -164,7 +166,7 @@ private static void setChannelInitializerHolders()
164166

165167
public static EventLoopGroup newEventLoopGroup(int threads, ThreadFactory factory)
166168
{
167-
return io_uring ? new IOUringEventLoopGroup( threads, factory ) : epoll ? new EpollEventLoopGroup( threads, factory ) : new NioEventLoopGroup( threads, factory );
169+
return new MultiThreadIoEventLoopGroup( threads, factory, io_uring ? IoUringIoHandler.newFactory() : epoll ? EpollIoHandler.newFactory() : NioIoHandler.newFactory() );
168170
}
169171

170172
public static Class<? extends ServerChannel> getServerChannel(SocketAddress address)
@@ -176,7 +178,7 @@ public static Class<? extends ServerChannel> getServerChannel(SocketAddress addr
176178
return EpollServerDomainSocketChannel.class;
177179
}
178180

179-
return io_uring ? IOUringServerSocketChannel.class : epoll ? EpollServerSocketChannel.class : NioServerSocketChannel.class;
181+
return io_uring ? IoUringServerSocketChannel.class : epoll ? EpollServerSocketChannel.class : NioServerSocketChannel.class;
180182
}
181183

182184
public static Class<? extends Channel> getChannel(SocketAddress address)
@@ -188,12 +190,12 @@ public static Class<? extends Channel> getChannel(SocketAddress address)
188190
return EpollDomainSocketChannel.class;
189191
}
190192

191-
return io_uring ? IOUringSocketChannel.class : epoll ? EpollSocketChannel.class : NioSocketChannel.class;
193+
return io_uring ? IoUringSocketChannel.class : epoll ? EpollSocketChannel.class : NioSocketChannel.class;
192194
}
193195

194196
public static Class<? extends DatagramChannel> getDatagramChannel()
195197
{
196-
return io_uring ? IOUringDatagramChannel.class : epoll ? EpollDatagramChannel.class : NioDatagramChannel.class;
198+
return io_uring ? IoUringDatagramChannel.class : epoll ? EpollDatagramChannel.class : NioDatagramChannel.class;
197199
}
198200

199201
private static final int LOW_MARK = Integer.getInteger( "net.md_5.bungee.low_mark", 2 << 18 ); // 0.5 mb
@@ -217,6 +219,8 @@ public boolean accept(Channel ch)
217219
{
218220
// IP_TOS is not supported (Windows XP / Windows Server 2003)
219221
}
222+
// https://github.com/netty/netty/wiki/Netty-4.2-Migration-Guide
223+
// TODO: check for AdaptiveByteBufAllocator
220224
ch.config().setAllocator( PooledByteBufAllocator.DEFAULT );
221225
ch.config().setWriteBufferWaterMark( MARK );
222226

0 commit comments

Comments
 (0)