Fix StackOverflowError in LocalEcho.doBeginRead() when the peer channel keeps writing data
- Fixes #1380
This commit is contained in:
parent
5398792ffa
commit
a3b4cdd614
@ -43,7 +43,24 @@ public class LocalChannel extends AbstractChannel {
|
|||||||
|
|
||||||
private static final ChannelMetadata METADATA = new ChannelMetadata(BufType.MESSAGE, false);
|
private static final ChannelMetadata METADATA = new ChannelMetadata(BufType.MESSAGE, false);
|
||||||
|
|
||||||
|
private static final int MAX_READER_STACK_DEPTH = 8;
|
||||||
|
private static final ThreadLocal<Integer> READER_STACK_DEPTH = new ThreadLocal<Integer>() {
|
||||||
|
@Override
|
||||||
|
protected Integer initialValue() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private final ChannelConfig config = new DefaultChannelConfig(this);
|
private final ChannelConfig config = new DefaultChannelConfig(this);
|
||||||
|
private final Runnable readTask = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ChannelPipeline pipeline = pipeline();
|
||||||
|
pipeline.fireInboundBufferUpdated();
|
||||||
|
pipeline.fireChannelReadSuspended();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private final Runnable shutdownHook = new Runnable() {
|
private final Runnable shutdownHook = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -225,8 +242,18 @@ public class LocalChannel extends AbstractChannel {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pipeline.fireInboundBufferUpdated();
|
final Integer stackDepth = READER_STACK_DEPTH.get();
|
||||||
pipeline.fireChannelReadSuspended();
|
if (stackDepth < MAX_READER_STACK_DEPTH) {
|
||||||
|
READER_STACK_DEPTH.set(stackDepth + 1);
|
||||||
|
try {
|
||||||
|
pipeline.fireInboundBufferUpdated();
|
||||||
|
pipeline.fireChannelReadSuspended();
|
||||||
|
} finally {
|
||||||
|
READER_STACK_DEPTH.set(stackDepth);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eventLoop().execute(readTask);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user