Make sure all resources of a ByteBridge and MessageBridge are released
This commit is contained in:
parent
547d4c20b0
commit
e3b8f4dea8
@ -338,6 +338,8 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
|
|||||||
((ChannelInboundHandler) handler).freeInboundBuffer(this);
|
((ChannelInboundHandler) handler).freeInboundBuffer(this);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
pipeline.notifyHandlerException(e);
|
pipeline.notifyHandlerException(e);
|
||||||
|
} finally {
|
||||||
|
freeInboundBridge();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (handler instanceof ChannelOutboundHandler) {
|
if (handler instanceof ChannelOutboundHandler) {
|
||||||
@ -345,10 +347,36 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
|
|||||||
((ChannelOutboundHandler) handler).freeOutboundBuffer(this);
|
((ChannelOutboundHandler) handler).freeOutboundBuffer(this);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
pipeline.notifyHandlerException(e);
|
pipeline.notifyHandlerException(e);
|
||||||
|
} finally {
|
||||||
|
freeOutboundBridge();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void freeInboundBridge() {
|
||||||
|
ByteBridge inByteBridge = this.inByteBridge;
|
||||||
|
if (inByteBridge != null) {
|
||||||
|
inByteBridge.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBridge inMsgBridge = this.inMsgBridge;
|
||||||
|
if (inMsgBridge != null) {
|
||||||
|
inMsgBridge.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void freeOutboundBridge() {
|
||||||
|
ByteBridge outByteBridge = this.outByteBridge;
|
||||||
|
if (outByteBridge != null) {
|
||||||
|
outByteBridge.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBridge outMsgBridge = this.outMsgBridge;
|
||||||
|
if (outMsgBridge != null) {
|
||||||
|
outMsgBridge.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Channel channel() {
|
public Channel channel() {
|
||||||
return channel;
|
return channel;
|
||||||
@ -680,6 +708,9 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
|
|||||||
if (bridge == null) {
|
if (bridge == null) {
|
||||||
bridge = new ByteBridge(ctx);
|
bridge = new ByteBridge(ctx);
|
||||||
if (!IN_BYTE_BRIDGE_UPDATER.compareAndSet(ctx, null, bridge)) {
|
if (!IN_BYTE_BRIDGE_UPDATER.compareAndSet(ctx, null, bridge)) {
|
||||||
|
// release it as it was set before
|
||||||
|
bridge.release();
|
||||||
|
|
||||||
bridge = ctx.inByteBridge;
|
bridge = ctx.inByteBridge;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -705,6 +736,9 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
|
|||||||
if (bridge == null) {
|
if (bridge == null) {
|
||||||
bridge = new MessageBridge();
|
bridge = new MessageBridge();
|
||||||
if (!IN_MSG_BRIDGE_UPDATER.compareAndSet(ctx, null, bridge)) {
|
if (!IN_MSG_BRIDGE_UPDATER.compareAndSet(ctx, null, bridge)) {
|
||||||
|
// release it as it was set before
|
||||||
|
bridge.release();
|
||||||
|
|
||||||
bridge = ctx.inMsgBridge;
|
bridge = ctx.inMsgBridge;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -730,6 +764,9 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
|
|||||||
if (bridge == null) {
|
if (bridge == null) {
|
||||||
bridge = new ByteBridge(ctx);
|
bridge = new ByteBridge(ctx);
|
||||||
if (!OUT_BYTE_BRIDGE_UPDATER.compareAndSet(ctx, null, bridge)) {
|
if (!OUT_BYTE_BRIDGE_UPDATER.compareAndSet(ctx, null, bridge)) {
|
||||||
|
// release it as it was set before
|
||||||
|
bridge.release();
|
||||||
|
|
||||||
bridge = ctx.outByteBridge;
|
bridge = ctx.outByteBridge;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -755,6 +792,9 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
|
|||||||
if (bridge == null) {
|
if (bridge == null) {
|
||||||
bridge = new MessageBridge();
|
bridge = new MessageBridge();
|
||||||
if (!OUT_MSG_BRIDGE_UPDATER.compareAndSet(ctx, null, bridge)) {
|
if (!OUT_MSG_BRIDGE_UPDATER.compareAndSet(ctx, null, bridge)) {
|
||||||
|
// release it as it was set before
|
||||||
|
bridge.release();
|
||||||
|
|
||||||
bridge = ctx.outMsgBridge;
|
bridge = ctx.outMsgBridge;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1520,6 +1560,8 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
|
|||||||
h.freeInboundBuffer(this);
|
h.freeInboundBuffer(this);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
pipeline.notifyHandlerException(t);
|
pipeline.notifyHandlerException(t);
|
||||||
|
} finally {
|
||||||
|
freeInboundBridge();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1560,6 +1602,8 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
|
|||||||
h.freeOutboundBuffer(this);
|
h.freeOutboundBuffer(this);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
pipeline.notifyHandlerException(t);
|
pipeline.notifyHandlerException(t);
|
||||||
|
} finally {
|
||||||
|
freeOutboundBridge();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1647,6 +1691,10 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
|
|||||||
Collections.addAll(out, data);
|
Collections.addAll(out, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void release() {
|
||||||
|
msgBuf.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class ByteBridge {
|
private static final class ByteBridge {
|
||||||
@ -1700,5 +1748,9 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void release() {
|
||||||
|
byteBuf.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user