Skip to content

Crash in channelClosed #624

@fabianfett

Description

@fabianfett

Describe the bug

When running the lambda tests we observed a crash in:

    private func channelClosed(_ channel: any Channel) {
        switch (self.connectionState, self.closingState) {
        case (_, .closed):
            fatalError("Invalid state: \(self.connectionState), \(self.closingState)") // <---- crash

fatalError log:

AWSLambdaRuntime/LambdaRuntimeClient.swift:270: Fatal error: Invalid state: connected(SocketChannel { BaseSocket { fd=214 }, active = false, localAddress = Optional([IPv4]127.0.0.1/127.0.0.1:36846), remoteAddress = Optional([IPv4]127.0.0.1/127.0.0.1:33103) }, AWSLambdaRuntime.LambdaChannelHandler<AWSLambdaRuntime.LambdaRuntimeClient>), closed

Crash - Logs:

Thread 34 "NIO-SGLTN-1-#12" crashed:

  0               0x00007f5df91f9718 _assertionFailure(_:_:file:line:flags:) + 264 in libswiftCore.so
  1 [ra]          0x0000560234e37935 LambdaRuntimeClient.channelClosed(_:) + 1636 in swift-aws-lambda-runtimePackageTests.xctest at /workspace/session/repos/swift-aws-lambda-runtime/Sources/AWSLambdaRuntime/HTTPClient/LambdaRuntimeClient.swift:270:13
  2 [ra]          0x0000560234918a8d closure #1 in closure #3 in LambdaRuntimeClient.makeOrGetConnection() + 188 in swift-aws-lambda-runtimePackageTests.xctest at /workspace/session/repos/swift-aws-lambda-runtime/Sources/AWSLambdaRuntime/HTTPClient/LambdaRuntimeClient.swift:371:35
  3 [ra] [thunk]  0x000056023491c234 partial apply for closure #1 in closure #3 in LambdaRuntimeClient.makeOrGetConnection() + 19 in swift-aws-lambda-runtimePackageTests.xctest at //<compiler-generated>
  4 [ra] [thunk]  0x000056023491bf8f thunk for @callee_guaranteed (@guaranteed isolated A) -> (@out A1, @error @owned Error) + 14 in swift-aws-lambda-runtimePackageTests.xctest at //<compiler-generated>
  5 [ra] [thunk]  0x000056023491c01b partial apply for thunk for @callee_guaranteed (@guaranteed isolated A) -> (@out A1, @error @owned Error) + 42 in swift-aws-lambda-runtimePackageTests.xctest at //<compiler-generated>
  6 [ra] [thunk]  0x000056023491c162 thunk for @escaping @callee_guaranteed (@guaranteed isolated A) -> (@out A1, @error @owned Error) + 17 in swift-aws-lambda-runtimePackageTests.xctest at //<compiler-generated>
  7 [ra] [thunk]  0x000056023491c20b partial apply for thunk for @escaping @callee_guaranteed (@guaranteed isolated A) -> (@out A1, @error @owned Error) + 42 in swift-aws-lambda-runtimePackageTests.xctest at //<compiler-generated>
  8 [ra] [system] 0x000056023491c0e6 closure #1 in Actor.assumeIsolated<A>(_:file:line:) + 181 in swift-aws-lambda-runtimePackageTests.xctest at //<compiler-generated>
  9 [ra] [system] 0x0000560234918cd6 Actor.assumeIsolated<A>(_:file:line:) + 469 in swift-aws-lambda-runtimePackageTests.xctest at //<compiler-generated>
 10 [ra]          0x00005602349189a1 closure #3 in LambdaRuntimeClient.makeOrGetConnection() + 208 in swift-aws-lambda-runtimePackageTests.xctest at /workspace/session/repos/swift-aws-lambda-runtime/Sources/AWSLambdaRuntime/HTTPClient/LambdaRuntimeClient.swift:369:22
 11 [ra]          0x0000560234c48341 closure #1 in EventLoopFuture.whenComplete(_:) + 368 in swift-aws-lambda-runtimePackageTests.xctest at /workspace/session/repos/swift-nio/Sources/NIOCore/EventLoopFuture.swift:900:13
 12 [ra]          0x0000560234f99b36 CallbackList._run() + 517 in swift-aws-lambda-runtimePackageTests.xctest at /workspace/session/repos/swift-nio/Sources/NIOCore/EventLoopFuture.swift:106:40
 13 [ra]          0x0000560234f9a3f2 EventLoopPromise._resolve<A>(value:) + 273 in swift-aws-lambda-runtimePackageTests.xctest at /workspace/session/repos/swift-nio/Sources/NIOCore/EventLoopFuture.swift:280:42
 14 [ra]          0x0000560234f9a2c1 EventLoopPromise.succeed(_:) + 176 in swift-aws-lambda-runtimePackageTests.xctest at /workspace/session/repos/swift-nio/Sources/NIOCore/EventLoopFuture.swift:214:14
 15 [ra]          0x0000560234d09550 closure #3 in BaseSocketChannel.close0(error:mode:promise:) + 159 in swift-aws-lambda-runtimePackageTests.xctest at /workspace/session/repos/swift-nio/Sources/NIOPosix/BaseSocketChannel.swift:922:31
 16 [ra]          0x0000560234d7ac80 closure #1 in SelectableEventLoop.run(_:) + 175 in swift-aws-lambda-runtimePackageTests.xctest at /workspace/session/repos/swift-nio/Sources/NIOPosix/SelectableEventLoop.swift:616:17
 17 [ra] [thunk]  0x0000560234d7f044 partial apply for closure #1 in SelectableEventLoop.run(_:) + 19 in swift-aws-lambda-runtimePackageTests.xctest at //<compiler-generated>
 18 [ra]          0x0000560235097eb2 withAutoReleasePool<A>(_:) + 33 in swift-aws-lambda-runtimePackageTests.xctest at /workspace/session/repos/swift-nio/Sources/NIOPosix/SelectableEventLoop.swift:47:16
 19 [ra]          0x000056023509be00 SelectableEventLoop.run(_:) + 95 in swift-aws-lambda-runtimePackageTests.xctest at /workspace/session/repos/swift-nio/Sources/NIOPosix/SelectableEventLoop.swift:613:9
 20 [ra]          0x000056023509d010 SelectableEventLoop.runOneLoopTick(selfIdentifier:) + 1311 in swift-aws-lambda-runtimePackageTests.xctest at /workspace/session/repos/swift-nio/Sources/NIOPosix/SelectableEventLoop.swift:807:22
 21 [ra]          0x000056023509d508 SelectableEventLoop.run() + 695 in swift-aws-lambda-runtimePackageTests.xctest at /workspace/session/repos/swift-nio/Sources/NIOPosix/SelectableEventLoop.swift:921:38
 22 [ra]          0x000056023507aa09 static MultiThreadedEventLoopGroup.runTheLoop(thread:uniqueID:parentGroup:canEventLoopBeShutdownIndividually:selectorFactory:initializer:metricsDelegate:_:) + 968 in swift-aws-lambda-runtimePackageTests.xctest at /workspace/session/repos/swift-nio/Sources/NIOPosix/MultiThreadedEventLoopGroup.swift:115:22
 23 [ra]          0x0000560234d401a0 closure #1 in static MultiThreadedEventLoopGroup.setupThreadAndEventLoop(name:uniqueID:parentGroup:selectorFactory:initializer:metricsDelegate:) + 415 in swift-aws-lambda-runtimePackageTests.xctest at /workspace/session/repos/swift-nio/Sources/NIOPosix/MultiThreadedEventLoopGroup.swift:137:41
 24 [ra] [thunk]  0x0000560234d43808 partial apply for closure #1 in static MultiThreadedEventLoopGroup.setupThreadAndEventLoop(name:uniqueID:parentGroup:selectorFactory:initializer:metricsDelegate:) + 87 in swift-aws-lambda-runtimePackageTests.xctest at //<compiler-generated>
 25 [ra] [thunk]  0x0000560234d9816f thunk for @escaping @callee_guaranteed (@guaranteed NIOThread) -> () + 14 in swift-aws-lambda-runtimePackageTests.xctest at //<compiler-generated>
 26 [ra]          0x0000560234d995e8 closure #1 in closure #1 in static ThreadOpsPosix.run(handle:args:) + 887 in swift-aws-lambda-runtimePackageTests.xctest at /workspace/session/repos/swift-nio/Sources/NIOPosix/ThreadPosix.swift:184:21
 27 [ra] [thunk]  0x0000560234d996a9 @objc closure #1 in closure #1 in static ThreadOpsPosix.run(handle:args:) + 8 in swift-aws-lambda-runtimePackageTests.xctest at //<compiler-generated>

Expected Behavior

Should not crash.

Current Behavior

Crashes.

Reproduction Steps

Run tests. Might crash eventually. Crashed on 6.0.

Possible Solution

No response

Additional Information/Context

No response

AWS SWIFT SDK version used

main

Compiler and Version used

Swift 6.0

Operating System and version

x86_64 Linux (Red Hat Enterprise Linux 9.7 (Plow))

Metadata

Metadata

Assignees

Labels

kind/bugFeature doesn't work as expected.platform/linuxLinux platform specific issues.size/SSmall task. (A couple of hours of work.)🔨 semver/patchNo public API change.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions