apple / swift-nio

Event-driven network application framework for high performance protocol servers & clients, non-blocking.
https://swiftpackageindex.com/apple/swift-nio/documentation
Apache License 2.0
7.99k stars 651 forks source link

channelRead invoked before channelActive #196

Open vlm opened 6 years ago

vlm commented 6 years ago

Expected behavior

The Channel callbacks lifecycle should start with channelActive and end with channelInactive.

Actual behavior

Sometimes under high concurrency the channelRead is invoked prior to channelActive.

Steps to reproduce

Run the attached code.

The code fails in one of three ways:

  1. It either gets stuck
  2. Or it fails with Illegal Instruction on a DispatchQueue (entering some q.sync)
  3. Or it fails with
    Precondition failed: channelRead before channelActive!: file StuckTest/RemoteSystem.swift, line 224
    Illegal instruction: 4

The first two failures might not be relevant, but it warrants to take a look. This particular issue is mainly about failure number 3, Precondition failed.

Minimal yet complete reproducer code

StuckTest.zip

SwiftNIO version/commit hash

681ddd8bab4fac997cbc70ca15a1e13c74da50b9 (nmaurer/order_fix)

Swift & OS version (output of swift --version && uname -a)

Apple Swift version 4.1 (swiftlang-902.0.38 clang-902.0.30) Target: x86_64-apple-darwin17.4.0 Darwin Levs-MacBook-Pro.local 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64 x86_64

vlm commented 6 years ago

FYI: https://github.com/apple/swift-nio/pull/195 did not help.

normanmaurer commented 6 years ago

Thanks... will have a look later today 👍

Am 20.03.2018 um 02:07 schrieb Lev Walkin notifications@github.com:

FYI: #195 did not help.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

vlm commented 6 years ago

FYI: https://github.com/apple/swift-nio/pull/204 did not help either. It just made it pop up a bit less frequently.

weissi commented 4 months ago

This could still be happening. Probably related to #2773 . The recipe for bad stuff would be to trigger operations from the connect promise. Then they come in after the channel is fully active, but before we call channelActive.