Fix #10434 OutOfDirectMemoryError causes cpu load too high and socket is full (#10457)

Motivation:

When we were using the netty http protocol, OOM occurred, this problem has been in 4.1.51.Final Fix [# 10424](https://github.com/netty/netty/issues/10424), even if OOM is up, the service will still receive new connection events, will occur again OOM and eventually cause the connection not to be released.

code `byteBuf = allocHandle.allocate(allocator);`

Modification:

I fail to create buffer when I try to receive new data, i determine if it is OOM then the close read event releases the connection.
```java
        if (close || cause instanceof OutOfMemoryError || cause instanceof IOException) {
            closeOnRead(pipeline);
        }
```

Result:

Fixes # [10434](https://github.com/netty/netty/issues/10434).
This commit is contained in:
Kevin Wu 2020-08-13 16:14:19 +08:00 committed by Norman Maurer
parent 41313130a3
commit 223422cea3
3 changed files with 12 additions and 3 deletions

View File

@ -523,7 +523,10 @@ public abstract class AbstractEpollStreamChannel extends AbstractEpollChannel im
allocHandle.readComplete();
pipeline.fireChannelReadComplete();
pipeline.fireExceptionCaught(cause);
if (close || cause instanceof IOException) {
// If oom will close the read event, release connection.
// See https://github.com/netty/netty/issues/10434
if (close || cause instanceof OutOfMemoryError || cause instanceof IOException) {
shutdownInput(false);
} else {
readIfIsAutoRead();

View File

@ -568,7 +568,10 @@ public abstract class AbstractKQueueStreamChannel extends AbstractKQueueChannel
allocHandle.readComplete();
pipeline.fireChannelReadComplete();
pipeline.fireExceptionCaught(cause);
if (close || cause instanceof IOException) {
// If oom will close the read event, release connection.
// See https://github.com/netty/netty/issues/10434
if (close || cause instanceof OutOfMemoryError || cause instanceof IOException) {
shutdownInput(false);
} else {
readIfIsAutoRead();

View File

@ -122,7 +122,10 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel {
allocHandle.readComplete();
pipeline.fireChannelReadComplete();
pipeline.fireExceptionCaught(cause);
if (close || cause instanceof IOException) {
// If oom will close the read event, release connection.
// See https://github.com/netty/netty/issues/10434
if (close || cause instanceof OutOfMemoryError || cause instanceof IOException) {
closeOnRead(pipeline);
} else {
readIfIsAutoRead();