Move OOM try-catch

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-10-25 10:08:25 +02:00
parent afdc67fc26
commit 1851ea7eca

View File

@ -276,7 +276,13 @@ public class PlayerSocketConnection extends PlayerConnection {
public void flush() { public void flush() {
try { try {
synchronized (bufferLock) { synchronized (bufferLock) {
updateLocalBuffer(); try {
updateLocalBuffer();
} catch (OutOfMemoryError e) {
this.waitingBuffers.clear();
System.gc(); // Explicit gc forcing buffers to be collected
throw new ClosedChannelException();
}
} }
synchronized (flushLock) { synchronized (flushLock) {
try { try {
@ -291,10 +297,6 @@ public class PlayerSocketConnection extends PlayerConnection {
} catch (IOException e) { // Couldn't write to the socket } catch (IOException e) { // Couldn't write to the socket
MinecraftServer.getExceptionManager().handleException(e); MinecraftServer.getExceptionManager().handleException(e);
throw new ClosedChannelException(); throw new ClosedChannelException();
} catch (OutOfMemoryError e) { // Couldn't allocate a pooled buffer
this.waitingBuffers.clear();
System.gc(); // Explicit gc forcing buffers to be collected
throw new ClosedChannelException();
} }
} }
} catch (ClosedChannelException e) { } catch (ClosedChannelException e) {