mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
[FIX] Утечка памяти из за пингов(!)
This commit is contained in:
parent
d7519688ee
commit
f9521b41a2
1 changed files with 9 additions and 1 deletions
|
@ -4,6 +4,7 @@
|
|||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.handler.codec.http.websocketx.*;
|
||||
import io.netty.util.concurrent.ScheduledFuture;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
import pro.gravit.launchserver.socket.NettyConnectContext;
|
||||
|
@ -23,6 +24,7 @@ public class WebSocketFrameHandler extends SimpleChannelInboundHandler<WebSocket
|
|||
public NettyConnectContext context;
|
||||
public final BiHookSet<ChannelHandlerContext, WebSocketFrame> hooks = new BiHookSet<>();
|
||||
private Client client;
|
||||
private ScheduledFuture<?> future;
|
||||
|
||||
public WebSocketFrameHandler(NettyConnectContext context, LaunchServer srv, WebSocketService service) {
|
||||
this.context = context;
|
||||
|
@ -50,7 +52,7 @@ public void channelActive(ChannelHandlerContext ctx) {
|
|||
client = new Client(null);
|
||||
Channel ch = ctx.channel();
|
||||
service.registerClient(ch);
|
||||
ctx.executor().scheduleAtFixedRate(() -> ch.writeAndFlush(new PingWebSocketFrame(), ch.voidPromise()), 30L, 30L, TimeUnit.SECONDS);
|
||||
future = ctx.executor().scheduleAtFixedRate(() -> ch.writeAndFlush(new PingWebSocketFrame(), ch.voidPromise()), 30L, 30L, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -92,4 +94,10 @@ protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) {
|
|||
LogHelper.error(new UnsupportedOperationException(message)); // prevent strange crash here.
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
if(future != null) future.cancel(true);
|
||||
super.channelInactive(ctx);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue