Skip to content
Permalink
Browse files

B2MH: helpful message if re-added to pipeline (#903)

Motivation:

B2MH used to crash a nil variable if re-added to a pipeline.

Modifications:

provide good error message for the crash instead

Result:

- fixes #902
  • Loading branch information...
weissi committed Mar 14, 2019
1 parent ccd386b commit 205f317fd94c2b773e08e729c0a6b61f0c7d6abf
Showing with 3 additions and 0 deletions.
  1. +3 −0 Sources/NIO/Codec.swift
@@ -461,6 +461,9 @@ extension ByteToMessageHandler {
extension ByteToMessageHandler: ChannelInboundHandler {

public func handlerAdded(context: ChannelHandlerContext) {
guard self.removalState == .notBeingRemoved else {
preconditionFailure("\(self) got readded to a ChannelPipeline but ByteToMessageHandler is single-use")
}
self.buffer = B2MDBuffer(emptyByteBuffer: context.channel.allocator.buffer(capacity: 0))
// here we can force it because we know that the decoder isn't in use if we're just adding this handler
self.selfAsCanDequeueWrites = self as? CanDequeueWrites // we need to cache this as it allocates.

0 comments on commit 205f317

Please sign in to comment.
You can’t perform that action at this time.