Skip to content
Browse files

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


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


provide good error message for the crash instead


- 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: 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.