Open weissi opened 2 months ago
The issues is that the connect promise gets (by design) priority over fireChannelActive
. The code's here: https://github.com/apple/swift-nio/blob/abbb144f6678d0d830899b8bda5eea5924a61c0d/Sources/NIOPosix/BaseSocketChannel.swift#L131-L132
case (.fullyRegistered, .activate):
self.currentState = .activated
return { promise, pipeline in
promise?.succeed(())
pipeline.syncOperations.fireChannelActive()
}
So NIO (like Netty) will always fulfil the promise first and then fire the channel pipeline event. That leads to this reorder:
Channel.connect
succeedsconnect
's promise gets fulfilledChannel.close()
in connect
promise callbackchannelInactive
gets called (because of the close
)channelActive
gets called once we move past the promise?.succeed(())
lineI think this is a rediscovery of https://github.com/apple/swift-nio/issues/196 . Please note this comment: https://github.com/apple/swift-nio/issues/196#issuecomment-374863576
Expected behavior
channelInactive
comes afterchannelActive
channelInactive
doesn't happen ifchannelActive
hasn't happenedActual behavior
It's possible to get
channelActive
followingchannelInactive
.Steps to reproduce
Channel.close()
d really early on.This seems related to https://github.com/apple/swift-nio-ssl/issues/467
NIOSSLHandler observes the channel events in this order:
NIOSSLHandler
sees the following channel events:handlerAdded
close
(triggered from aChannel.close()
)channelInactive
(triggered fromBaseSocketChannel.close0
) [BUG HERE (channelInactive
withoutchannelActive
)]channelActive
(triggered fromBaseSocketChannel.writable
->BaseSocketChannel.finishConnect
->BaseSocketChannel.becomeActive()
) [BUG HERE (channelActive
afterchannelInactive
)]Obviously those channel events are wrong. That's a bug in NIO too.