Skip to content

Commit

Permalink
Always close tick future when closing peer
Browse files Browse the repository at this point in the history
  • Loading branch information
Alemiz112 committed Jun 12, 2023
1 parent 9b01c3a commit 76a8533
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ protected void removeSession(BedrockSession session) {
}

protected void onTick() {
if (this.closed.get()) {
return;
}

if (!this.packetQueue.isEmpty()) {
BedrockPacketWrapper packet;
while ((packet = this.packetQueue.poll()) != null) {
Expand Down Expand Up @@ -190,10 +194,20 @@ public void close(String reason) {
}

protected void onClose() {
if (this.channel.isOpen() || !this.closed.compareAndSet(false, true)) {
if (this.channel.isOpen()) {
log.warn("Tried to close peer, but channel is open!", new Throwable());
return;
}

if (!this.closed.compareAndSet(false, true)) {
return;
}

if (this.tickFuture != null) {
this.tickFuture.cancel(false);
this.tickFuture = null;
}

for (BedrockSession session : this.sessions.values())
try {
session.onClose();
Expand Down Expand Up @@ -237,10 +251,6 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception {

@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
if (this.tickFuture != null) {
this.tickFuture.cancel(false);
this.tickFuture = null;
}
this.onClose();
}

Expand Down

0 comments on commit 76a8533

Please sign in to comment.