Skip to content
This repository was archived by the owner on Jun 7, 2022. It is now read-only.

Commit 6e74c06

Browse files
author
Dytanic
committed
fixed out of memory bug by network connection
1 parent 20c00be commit 6e74c06

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

cloudnet-lib/src/main/java/de/dytanic/cloudnet/lib/network/NetworkConnection.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import io.netty.bootstrap.Bootstrap;
1515
import io.netty.channel.*;
1616
import io.netty.handler.ssl.SslContext;
17+
import io.netty.handler.ssl.SslContextBuilder;
1718
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
1819
import lombok.AccessLevel;
1920
import lombok.Getter;
@@ -35,9 +36,9 @@ public final class NetworkConnection implements PacketSender {
3536
private long connectionTrys = 0;
3637

3738
private final PacketManager packetManager = new PacketManager();
38-
private EventLoopGroup eventLoopGroup = NetworkUtils.eventLoopGroup(4);
39-
private Runnable task;
39+
private final EventLoopGroup eventLoopGroup = NetworkUtils.eventLoopGroup(4);
4040

41+
private Runnable task;
4142
private SslContext sslContext;
4243

4344
@Override
@@ -66,8 +67,7 @@ public boolean tryConnect(boolean ssl, SimpleChannelInboundHandler<Packet> defau
6667
{
6768
try
6869
{
69-
eventLoopGroup = NetworkUtils.eventLoopGroup(4);
70-
if (ssl) sslContext = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE);
70+
if (ssl) sslContext = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
7171

7272
Bootstrap bootstrap = new Bootstrap()
7373
.option(ChannelOption.AUTO_READ, true)
@@ -95,10 +95,11 @@ protected void initChannel(Channel channel) throws Exception
9595
System.out.println("Failed to connect... [" + connectionTrys + "]");
9696
System.out.println("Error: " + ex.getMessage());
9797

98-
if (eventLoopGroup != null)
99-
eventLoopGroup.shutdownGracefully();
100-
101-
eventLoopGroup = null;
98+
if (this.channel != null)
99+
{
100+
this.channel.close();
101+
this.channel = null;
102+
}
102103

103104
if (cancelTask != null)
104105
{
@@ -113,6 +114,7 @@ public boolean tryDisconnect()
113114
{
114115
if (channel != null)
115116
channel.close();
117+
116118
eventLoopGroup.shutdownGracefully();
117119
return false;
118120
}

0 commit comments

Comments
 (0)