swift-nio icon indicating copy to clipboard operation
swift-nio copied to clipboard

NIO can send `channelInactive` before `channelActive` reordered if user `Channel.close()`s in `connect` promise callback

Open weissi opened this issue 7 months ago • 2 comments

Expected behavior

  • channelInactive comes after channelActive
  • channelInactive doesn't happen if channelActive hasn't happened

Actual behavior

It's possible to get channelActive following channelInactive.

Steps to reproduce

  • Create an SSL channel that gets 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 a Channel.close())
  • channelInactive (triggered from BaseSocketChannel.close0) [BUG HERE (channelInactive without channelActive)]
  • channelActive (triggered from BaseSocketChannel.writable -> BaseSocketChannel.finishConnect -> BaseSocketChannel.becomeActive()) [BUG HERE (channelActive after channelInactive)]

Obviously those channel events are wrong. That's a bug in NIO too.

weissi avatar Jul 09 '24 13:07 weissi