[#1511] Fix NPE in AbstractTrafficShapingHandler which could happen if the READ_SUSPEND attr was not set yet
This commit is contained in:
parent
a4ee2841be
commit
824bb3419a
@ -234,7 +234,7 @@ public abstract class AbstractTrafficShapingHandler extends ChannelDuplexHandler
|
|||||||
if (wait >= MINIMAL_WAIT) { // At least 10ms seems a minimal
|
if (wait >= MINIMAL_WAIT) { // At least 10ms seems a minimal
|
||||||
// time in order to
|
// time in order to
|
||||||
// try to limit the traffic
|
// try to limit the traffic
|
||||||
if (!ctx.attr(READ_SUSPENDED).get()) {
|
if (!isSuspended(ctx)) {
|
||||||
ctx.attr(READ_SUSPENDED).set(true);
|
ctx.attr(READ_SUSPENDED).set(true);
|
||||||
|
|
||||||
// Create a Runnable to reactive the read if needed. If one was create before it will just be
|
// Create a Runnable to reactive the read if needed. If one was create before it will just be
|
||||||
@ -266,12 +266,19 @@ public abstract class AbstractTrafficShapingHandler extends ChannelDuplexHandler
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(ChannelHandlerContext ctx) {
|
public void read(ChannelHandlerContext ctx) {
|
||||||
Boolean suspended = ctx.attr(READ_SUSPENDED).get();
|
if (!isSuspended(ctx)) {
|
||||||
if (suspended == null || Boolean.FALSE.equals(suspended)) {
|
|
||||||
ctx.read();
|
ctx.read();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isSuspended(ChannelHandlerContext ctx) {
|
||||||
|
Boolean suspended = ctx.attr(READ_SUSPENDED).get();
|
||||||
|
if (suspended == null || Boolean.FALSE.equals(suspended)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(final ChannelHandlerContext ctx, final MessageList<Object> msgs, final ChannelPromise promise)
|
public void write(final ChannelHandlerContext ctx, final MessageList<Object> msgs, final ChannelPromise promise)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user