mirror of
https://github.com/apple/swift-nio
synced 2026-11-28 05:14:23 +00:00
remove bogus 'is active' assertion in channelRead0 (#740)
(cherry picked from commit 722ceb869d)
Motivation:
BaseSocketChannel used to assert that `channelRead0` is only called when
the channel is active. That's bogus and it's trivial to hit this issue
when calling `fireChannelRead` in the last `ChannelHandler` when the
channel has gone inactive.
Modifications:
remove assertion, add comment
Result:
fewer crashes
This commit is contained in:
1 parent
37237d880c
commit
37457897d9
3 files changed
+29
-1
No files matched your search
@@ -1076,8 +1076,8 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
|
||||
}
|
||||
|
||||
public func channelRead0(_ data: NIOAny) {
|
||||
assert(self.lifecycleManager.isActive)
|
||||
// Do nothing by default
|
||||
// note: we can't assert that we're active here as TailChannelHandler will call this on channelRead
|
||||
}
|
||||
|
||||
public func errorCaught0(error: Error) {
|
||||
|
||||
@@ -51,6 +51,7 @@ extension ChannelPipelineTest {
|
||||
("testRemovingByNameWithFutureNotInChannel", testRemovingByNameWithFutureNotInChannel),
|
||||
("testRemovingByReferenceWithPromiseStillInChannel", testRemovingByReferenceWithPromiseStillInChannel),
|
||||
("testRemovingByReferenceWithFutureNotInChannel", testRemovingByReferenceWithFutureNotInChannel),
|
||||
("testFireChannelReadInInactiveChannelDoesNotCrash", testFireChannelReadInInactiveChannelDoesNotCrash),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -902,4 +902,31 @@ class ChannelPipelineTest: XCTestCase {
|
||||
XCTAssertNil(channel.readOutbound())
|
||||
XCTAssertNoThrow(try channel.throwIfErrorCaught())
|
||||
}
|
||||
|
||||
func testFireChannelReadInInactiveChannelDoesNotCrash() throws {
|
||||
class FireWhenInactiveHandler: ChannelInboundHandler {
|
||||
typealias InboundIn = ()
|
||||
typealias InboundOut = ()
|
||||
|
||||
func channelInactive(ctx: ChannelHandlerContext) {
|
||||
ctx.fireChannelRead(self.wrapInboundOut(()))
|
||||
}
|
||||
}
|
||||
let handler = FireWhenInactiveHandler()
|
||||
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
|
||||
defer {
|
||||
XCTAssertNoThrow(try group.syncShutdownGracefully())
|
||||
}
|
||||
let server = try assertNoThrowWithValue(ServerBootstrap(group: group).bind(host: "127.0.0.1", port: 0).wait())
|
||||
defer {
|
||||
XCTAssertNoThrow(try server.close().wait())
|
||||
}
|
||||
let client = try assertNoThrowWithValue(ClientBootstrap(group: group)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.add(handler: handler)
|
||||
}
|
||||
.connect(to: server.localAddress!)
|
||||
.wait())
|
||||
XCTAssertNoThrow(try client.close().wait())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user