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.93k stars 645 forks source link

`VsockAddressTest.testGetLocalCID` crashes in jammy with Swift 5.9.1 #2585

Closed fabianfett closed 10 months ago

fabianfett commented 10 months ago

When running the SwiftNIO tests on a:

fabian@swift-dev:~/dev/swift-nio$ uname -a
Linux swift-dev 5.15.0-88-generic #98-Ubuntu SMP Mon Oct 2 15:18:56 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

using:

fabian@swift-dev:~/dev/swift-nio$ swift --version
Swift version 5.9.1 (swift-5.9.1-RELEASE)
Target: x86_64-unknown-linux-gnu

I run into NIOPosix/VsockAddress.swift:228: Precondition failed. Full crash:

Test Case 'VsockAddressTest.testGetLocalCID' started at 2023-11-05 13:39:33.484
NIOPosix/VsockAddress.swift:228: Precondition failed
Current stack trace:
0    libswiftCore.so                    0x00007f86821186d0 _swift_stdlib_reportFatalErrorInFile + 109
1    libswiftCore.so                    0x00007f8681de4d85 <unavailable> + 1461637
2    libswiftCore.so                    0x00007f8681de4ba7 <unavailable> + 1461159
3    libswiftCore.so                    0x00007f8681de3b10 _assertionFailure(_:_:file:line:flags:) + 490
4    swift-nioPackageTests.xctest       0x00005572ca70da86 <unavailable> + 9153158
5    swift-nioPackageTests.xctest       0x00005572caafa80d <unavailable> + 13269005
6    swift-nioPackageTests.xctest       0x00005572ca61d8d1 <unavailable> + 8169681
7    swift-nioPackageTests.xctest       0x00005572caafa10a <unavailable> + 13267210
8    swift-nioPackageTests.xctest       0x00005572cac73dc6 <unavailable> + 14814662
9    swift-nioPackageTests.xctest       0x00005572cac752bf <unavailable> + 14820031
10   swift-nioPackageTests.xctest       0x00005572ca3a3a6f <unavailable> + 5573231
11   swift-nioPackageTests.xctest       0x00005572cac75314 <unavailable> + 14820116
12   libXCTest.so                       0x00007f86810bca7c <unavailable> + 223868
13   libXCTest.so                       0x00007f86810bc918 <unavailable> + 223512
14   libXCTest.so                       0x00007f86810bc8bf <unavailable> + 223423
15   libXCTest.so                       0x00007f86810bcbb6 <unavailable> + 224182
16   libXCTest.so                       0x00007f86810ae768 <unavailable> + 165736
17   libXCTest.so                       0x00007f86810ba790 XCTestCase.invokeTest() + 390
18   libXCTest.so                       0x00007f86810ba530 XCTestCase.perform(_:) + 147
19   libXCTest.so                       0x00007f86810be560 XCTest.run() + 144
20   libXCTest.so                       0x00007f86810bcd80 XCTestSuite.perform(_:) + 138
21   libXCTest.so                       0x00007f86810be560 XCTest.run() + 144
22   libXCTest.so                       0x00007f86810bcd80 XCTestSuite.perform(_:) + 138
23   libXCTest.so                       0x00007f86810be560 XCTest.run() + 144
24   libXCTest.so                       0x00007f86810bcd80 XCTestSuite.perform(_:) + 138
25   libXCTest.so                       0x00007f86810be560 XCTest.run() + 144
26   libXCTest.so                       0x00007f86810b9420 XCTMain(_:arguments:observers:) + 957
27   libXCTest.so                       0x00007f86810b9370 <unavailable> + 209776
28   swift-nioPackageTests.xctest       0x00005572cac9c1e1 <unavailable> + 14979553
29   swift-nioPackageTests.xctest       0x00005572cac9c1f9 <unavailable> + 14979577
30   swift-nioPackageTests.xctest       0x00005572cac9c219 <unavailable> + 14979609
31   libc.so.6                          0x00007f8680d9ad90 <unavailable> + 171408
32   libc.so.6                          0x00007f8680d9adc0 __libc_start_main + 128
33   swift-nioPackageTests.xctest       0x00005572c9f4d895 <unavailable> + 1026197
*** Program crashed: Illegal instruction at 0x00007f8681de3d06 ***

Thread 0 "swift-nioPackag" crashed:
0              0x00007f8681de3d06 _assertionFailure(_:_:file:line:flags:) + 502 in libswiftCore.so
1 [ra]         0x00005572ca70da86 static VsockAddress.ContextID.getLocalContextID(_:) + 709 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/VsockAddress.swift:228:9
2 [ra]         0x00005572caafa80d implicit closure #3 in VsockAddressTest.testGetLocalCID() + 28 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Tests/NIOPosixTests/VsockAddressTest.swift:63:75
3 [ra]         0x00005572ca61d8d1 BaseSocket.withUnsafeHandle<A>(_:) + 208 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/BaseSocket.swift:364:20
4 [ra]         0x00005572caafa10a VsockAddressTest.testGetLocalCID() + 265 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Tests/NIOPosixTests/VsockAddressTest.swift:63:35
5 [ra]         0x00005572cac73dc6 implicit closure #4 in implicit closure #3 in variable initialization expression of static VsockAddressTest.__allTests__VsockAddressTest + 37 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/.build/x86_64-unknown-linux-gnu/debug/swift-nioPackageDiscoveredTests.derived/NIOPosixTests.swift:929:29
6 [ra] [thunk] 0x00005572cac752bf partial apply for implicit closure #4 in implicit closure #3 in variable initialization expression of static VsockAddressTest.__allTests__VsockAddressTest + 14 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/<compiler-generated>
7 [ra] [thunk] 0x00005572ca3a3a6f thunk for @escaping @callee_guaranteed () -> (@error @owned Error) + 14 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/<compiler-generated>
8 [ra] [thunk] 0x00005572cac75314 partial apply for thunk for @escaping @callee_guaranteed () -> (@error @owned Error) + 19 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/<compiler-generated>

Thread 1:

0  0x00007f8680e9701e <unknown> in libc.so.6

Thread 2 "NIO-SGLTN-13-#0":
0              0x00007f8680e9701e <unknown> in libc.so.6
 1 [ra] [thunk] 0x00005572ca67cccc partial apply for closure #1 in static Epoll.epoll_wait(epfd:events:maxevents:timeout:) + 27 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/<compiler-generated>
 2 [ra]         0x00005572ca6fee4f syscall<A>(blocking:where:_:) + 382 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/System.swift:266:23
 3 [ra]         0x00005572ca67cbb5 static Epoll.epoll_wait(epfd:events:maxevents:timeout:) + 244 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/Linux.swift:121:20
 4 [ra]         0x00005572ca6d6d4d Selector.whenReady0(strategy:onLoopBegin:_:) + 1868 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/SelectorEpoll.swift:211:35
 5 [ra]         0x00005572ca6ddf74 Selector.whenReady(strategy:onLoopBegin:_:) + 99 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/SelectorGeneric.swift:288:18
 6 [ra]         0x00005572ca6ce90e closure #2 in SelectableEventLoop.run() + 157 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/SelectableEventLoop.swift:470:36
 7 [ra] [thunk] 0x00005572ca6d2cd4 partial apply for closure #2 in SelectableEventLoop.run() + 19 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/<compiler-generated>
 8 [ra]         0x00005572ca6c8cb2 withAutoReleasePool<A>(_:) + 33 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/SelectableEventLoop.swift:29:16
 9 [ra]         0x00005572ca6cda4e SelectableEventLoop.run() + 653 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/SelectableEventLoop.swift:469:17
10 [ra]         0x00005572ca67f4a2 static MultiThreadedEventLoopGroup.runTheLoop(thread:parentGroup:canEventLoopBeShutdownIndividually:selectorFactory:initializer:_:) + 817 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/MultiThreadedEventLoopGroup.swift:93:22
11 [ra]         0x00005572ca67fb6d closure #1 in static MultiThreadedEventLoopGroup.setupThreadAndEventLoop(name:parentGroup:selectorFactory:initializer:) + 332 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/MultiThreadedEventLoopGroup.swift:114:41
12 [ra] [thunk] 0x00005572ca686cec partial apply for closure #1 in static MultiThreadedEventLoopGroup.setupThreadAndEventLoop(name:parentGroup:selectorFactory:initializer:) + 59 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/<compiler-generated>
13 [ra] [thunk] 0x00005572ca70883f thunk for @escaping @callee_guaranteed (@guaranteed NIOThread) -> () + 14 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/<compiler-generated>
14 [ra]         0x00005572ca70b21c closure #1 in static ThreadOpsPosix.run(handle:args:detachThread:) + 1099 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/ThreadPosix.swift:112:13
15 [ra] [thunk] 0x00005572ca70b319 @objc closure #1 in static ThreadOpsPosix.run(handle:args:detachThread:) + 8 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/<compiler-generated>
Thread 3 "NIO-SGLTN-13-#1":
0              0x00007f8680e9701e <unknown> in libc.so.6
 1 [ra] [thunk] 0x00005572ca67cccc partial apply for closure #1 in static Epoll.epoll_wait(epfd:events:maxevents:timeout:) + 27 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/<compiler-generated>
 2 [ra]         0x00005572ca6fee4f syscall<A>(blocking:where:_:) + 382 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/System.swift:266:23
 3 [ra]         0x00005572ca67cbb5 static Epoll.epoll_wait(epfd:events:maxevents:timeout:) + 244 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/Linux.swift:121:20
 4 [ra]         0x00005572ca6d6d4d Selector.whenReady0(strategy:onLoopBegin:_:) + 1868 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/SelectorEpoll.swift:211:35
 5 [ra]         0x00005572ca6ddf74 Selector.whenReady(strategy:onLoopBegin:_:) + 99 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/SelectorGeneric.swift:288:18
 6 [ra]         0x00005572ca6ce90e closure #2 in SelectableEventLoop.run() + 157 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/SelectableEventLoop.swift:470:36
 7 [ra] [thunk] 0x00005572ca6d2cd4 partial apply for closure #2 in SelectableEventLoop.run() + 19 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/<compiler-generated>
 8 [ra]         0x00005572ca6c8cb2 withAutoReleasePool<A>(_:) + 33 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/SelectableEventLoop.swift:29:16
 9 [ra]         0x00005572ca6cda4e SelectableEventLoop.run() + 653 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/SelectableEventLoop.swift:469:17
10 [ra]         0x00005572ca67f4a2 static MultiThreadedEventLoopGroup.runTheLoop(thread:parentGroup:canEventLoopBeShutdownIndividually:selectorFactory:initializer:_:) + 817 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/MultiThreadedEventLoopGroup.swift:93:22
11 [ra]         0x00005572ca67fb6d closure #1 in static MultiThreadedEventLoopGroup.setupThreadAndEventLoop(name:parentGroup:selectorFactory:initializer:) + 332 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/MultiThreadedEventLoopGroup.swift:114:41
12 [ra] [thunk] 0x00005572ca686cec partial apply for closure #1 in static MultiThreadedEventLoopGroup.setupThreadAndEventLoop(name:parentGroup:selectorFactory:initializer:) + 59 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/<compiler-generated>
13 [ra] [thunk] 0x00005572ca70883f thunk for @escaping @callee_guaranteed (@guaranteed NIOThread) -> () + 14 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/<compiler-generated>
14 [ra]         0x00005572ca70b21c closure #1 in static ThreadOpsPosix.run(handle:args:detachThread:) + 1099 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/ThreadPosix.swift:112:13
15 [ra] [thunk] 0x00005572ca70b319 @objc closure #1 in static ThreadOpsPosix.run(handle:args:detachThread:) + 8 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/<compiler-generated>

Thread 4 "NIO-SGLTN-13-#2":
0              0x00007f8680e9701e <unknown> in libc.so.6
 1 [ra] [thunk] 0x00005572ca67cccc partial apply for closure #1 in static Epoll.epoll_wait(epfd:events:maxevents:timeout:) + 27 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/<compiler-generated>
 2 [ra]         0x00005572ca6fee4f syscall<A>(blocking:where:_:) + 382 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/System.swift:266:23
 3 [ra]         0x00005572ca67cbb5 static Epoll.epoll_wait(epfd:events:maxevents:timeout:) + 244 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/Linux.swift:121:20
 4 [ra]         0x00005572ca6d6d4d Selector.whenReady0(strategy:onLoopBegin:_:) + 1868 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/SelectorEpoll.swift:211:35
 5 [ra]         0x00005572ca6ddf74 Selector.whenReady(strategy:onLoopBegin:_:) + 99 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/SelectorGeneric.swift:288:18
 6 [ra]         0x00005572ca6ce90e closure #2 in SelectableEventLoop.run() + 157 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/SelectableEventLoop.swift:470:36
 7 [ra] [thunk] 0x00005572ca6d2cd4 partial apply for closure #2 in SelectableEventLoop.run() + 19 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/<compiler-generated>
 8 [ra]         0x00005572ca6c8cb2 withAutoReleasePool<A>(_:) + 33 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/SelectableEventLoop.swift:29:16
 9 [ra]         0x00005572ca6cda4e SelectableEventLoop.run() + 653 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/SelectableEventLoop.swift:469:17
10 [ra]         0x00005572ca67f4a2 static MultiThreadedEventLoopGroup.runTheLoop(thread:parentGroup:canEventLoopBeShutdownIndividually:selectorFactory:initializer:_:) + 817 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/MultiThreadedEventLoopGroup.swift:93:22
11 [ra]         0x00005572ca67fb6d closure #1 in static MultiThreadedEventLoopGroup.setupThreadAndEventLoop(name:parentGroup:selectorFactory:initializer:) + 332 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/MultiThreadedEventLoopGroup.swift:114:41
12 [ra] [thunk] 0x00005572ca686cec partial apply for closure #1 in static MultiThreadedEventLoopGroup.setupThreadAndEventLoop(name:parentGroup:selectorFactory:initializer:) + 59 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/<compiler-generated>
13 [ra] [thunk] 0x00005572ca70883f thunk for @escaping @callee_guaranteed (@guaranteed NIOThread) -> () + 14 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/<compiler-generated>
14 [ra]         0x00005572ca70b21c closure #1 in static ThreadOpsPosix.run(handle:args:detachThread:) + 1099 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/ThreadPosix.swift:112:13
15 [ra] [thunk] 0x00005572ca70b319 @objc closure #1 in static ThreadOpsPosix.run(handle:args:detachThread:) + 8 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/<compiler-generated>

Thread 5 "NIO-SGLTN-13-#3":
0              0x00007f8680e9701e <unknown> in libc.so.6
 1 [ra] [thunk] 0x00005572ca67cccc partial apply for closure #1 in static Epoll.epoll_wait(epfd:events:maxevents:timeout:) + 27 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/<compiler-generated>
 2 [ra]         0x00005572ca6fee4f syscall<A>(blocking:where:_:) + 382 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/System.swift:266:23
 3 [ra]         0x00005572ca67cbb5 static Epoll.epoll_wait(epfd:events:maxevents:timeout:) + 244 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/Linux.swift:121:20
 4 [ra]         0x00005572ca6d6d4d Selector.whenReady0(strategy:onLoopBegin:_:) + 1868 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/SelectorEpoll.swift:211:35
 5 [ra]         0x00005572ca6ddf74 Selector.whenReady(strategy:onLoopBegin:_:) + 99 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/SelectorGeneric.swift:288:18
 6 [ra]         0x00005572ca6ce90e closure #2 in SelectableEventLoop.run() + 157 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/SelectableEventLoop.swift:470:36
 7 [ra] [thunk] 0x00005572ca6d2cd4 partial apply for closure #2 in SelectableEventLoop.run() + 19 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/<compiler-generated>
 8 [ra]         0x00005572ca6c8cb2 withAutoReleasePool<A>(_:) + 33 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/SelectableEventLoop.swift:29:16
 9 [ra]         0x00005572ca6cda4e SelectableEventLoop.run() + 653 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/SelectableEventLoop.swift:469:17
10 [ra]         0x00005572ca67f4a2 static MultiThreadedEventLoopGroup.runTheLoop(thread:parentGroup:canEventLoopBeShutdownIndividually:selectorFactory:initializer:_:) + 817 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/MultiThreadedEventLoopGroup.swift:93:22
11 [ra]         0x00005572ca67fb6d closure #1 in static MultiThreadedEventLoopGroup.setupThreadAndEventLoop(name:parentGroup:selectorFactory:initializer:) + 332 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/MultiThreadedEventLoopGroup.swift:114:41
12 [ra] [thunk] 0x00005572ca686cec partial apply for closure #1 in static MultiThreadedEventLoopGroup.setupThreadAndEventLoop(name:parentGroup:selectorFactory:initializer:) + 59 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/<compiler-generated>
13 [ra] [thunk] 0x00005572ca70883f thunk for @escaping @callee_guaranteed (@guaranteed NIOThread) -> () + 14 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/<compiler-generated>
14 [ra]         0x00005572ca70b21c closure #1 in static ThreadOpsPosix.run(handle:args:detachThread:) + 1099 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/Sources/NIOPosix/ThreadPosix.swift:112:13
15 [ra] [thunk] 0x00005572ca70b319 @objc closure #1 in static ThreadOpsPosix.run(handle:args:detachThread:) + 8 in swift-nioPackageTests.xctest at /home/fabian/dev/swift-nio/<compiler-generated>

Thread 6 "SGLTN-TP-#0":

0  0x00007f8680e02117 <unknown> in libc.so.6

Thread 7 "SGLTN-TP-#1":

0  0x00007f8680e02117 <unknown> in libc.so.6

Thread 8 "SGLTN-TP-#2":

0  0x00007f8680e02117 <unknown> in libc.so.6

Thread 9 "SGLTN-TP-#3":

0  0x00007f8680e02117 <unknown> in libc.so.6

Thread 10 "NIO-ELT-210-#0":

0  0x00007f8680e02117 <unknown> in libc.so.6

Thread 11 "NIO-ELT-210-#0":

0  0x00007f8680e02117 <unknown> in libc.so.6

Thread 12:

0  0x00007f8680e02117 <unknown> in libc.so.6

Thread 13:

0  0x00007f8680e02117 <unknown> in libc.so.6

Thread 14 "NIO-ELT-232-#0":

0  0x00007f8680e02117 <unknown> in libc.so.6

Thread 15 "NIO-ELT-210-#0":
0  0x00007f8680e02117 <unknown> in libc.so.6

Thread 16 "NIO-ELT-210-#0":

0  0x00007f8680e02117 <unknown> in libc.so.6

Thread 17 "NIO-ELT-232-#0":

0  0x00007f8680e02117 <unknown> in libc.so.6

Thread 18:

0  0x00007f8680e02117 <unknown> in libc.so.6

Registers:
rax 0x00007f8682088b10  55 48 89 e5 48 85 ff 7e 26 48 b9 00 00 00 00 fe  UH·åH·ÿ~&H¹····þ
rdx 0x00005572cba43fd0  50 72 65 63 6f 6e 64 69 74 69 6f 6e 20 66 61 69  Precondition fai
rcx 0x00007f8682088b10  55 48 89 e5 48 85 ff 7e 26 48 b9 00 00 00 00 fe  UH·åH·ÿ~&H¹····þ
rbx 0x000055779a43d16c  93972177604972
rsi 0x8000000000000000  9223372036854775808
rdi 0x00005572cd0b5010  04 00 04 00 02 00 07 00 02 00 00 00 07 00 07 00  ················
rbp 0x00007ffe7c2abf50  a0 c0 2a 7c fe 7f 00 00 86 da 70 ca 72 55 00 00   À*|þ····ÚpÊrU··
rsp 0x00007ffe7c2abeb0  31 00 00 00 00 00 00 00 32 00 00 00 00 00 00 00  1·······2·······
r8 0x00005572cd6eca50  6c d1 43 9a 77 55 00 00 2c 9b a1 63 ab ff 67 ef  lÑC·wU··,·¡c«ÿgï
r9 0x00007ffe7c2abbf0  50 72 65 63 6f 6e 64 69 74 69 6f 6e 20 66 61 69  Precondition fai
r10 0x00005572cba43fc0  66 65 72 65 6e 63 65 2e 73 77 69 66 74 00 00 00  ference.swift···
r11 0xef67ffab63a19b2c  17251038009242000172
r12 0x0000000000000000  0
r13 0x0000000000000000  0
r14 0xe000000000000000  16140901064495857664
r15 0x0000000000000013  19
rip 0x00007f8681de3d06  0f 0b 48 83 ec 08 48 8d 05 dd dc 41 00 48 8d 3d  ··H·ì·H··ÝÜA·H·=
rflags 0x0000000000010286  SF PF
cs 0x0033  fs 0x0000  gs 0x0000
Images (17 omitted):
0x00005572c9e53000–0x00005572cb9f5ac0 <no build ID>                            swift-nioPackageTests.xctest /home/fabian/dev/swift-nio/.build/x86_64-unknown-linux-gnu/debug/swift-nioPackageTests.xctest
0x00007f8680d71000–0x00007f8680f2d541 a43bfc8428df6623cd498c9c0caeb91aec9be4f9 libc.so.6                    /usr/lib/x86_64-linux-gnu/libc.so.6
0x00007f8681c80000–0x00007f86821c6bf0 <no build ID>                            libswiftCore.so              /home/fabian/.local/share/swiftly/toolchains/5.9.1/usr/lib/swift/linux/libswiftCore.so
error: Exited with signal code 4
Lukasa commented 10 months ago

@simonjbeaumont can you take a look at this?

simonjbeaumont commented 10 months ago

Can you confirm whether your container has /dev/vsock and if you are starting it with --privileged?

❯ docker run --privileged --rm -v $PWD:/code -w /code -it swift:5.9.1-jammy ls /dev/vsock
/dev/vsock

❯ docker run --rm -v $PWD:/code -w /code -it swift:5.9.1-jammy ls /dev/vsock
ls: cannot access '/dev/vsock': No such file or directory

FWIW, I can run this test without a crash with swift:5.9.1-jammy with --privileged:

❯ docker run --privileged --rm -v $PWD:/code -w /code -it swift:5.9.1-jammy swift test --filter VsockAddressTest.testGetLocalCID
Building for debugging...
Build complete! (6.90s)
Test Suite 'Selected tests' started at 2023-11-06 13:18:07.422
Test Suite 'VsockAddressTest' started at 2023-11-06 13:18:07.424
Test Case 'VsockAddressTest.testGetLocalCID' started at 2023-11-06 13:18:07.424
Test Case 'VsockAddressTest.testGetLocalCID' passed (0.004 seconds)
Test Suite 'VsockAddressTest' passed at 2023-11-06 13:18:07.427
         Executed 1 test, with 0 failures (0 unexpected) in 0.004 (0.004) seconds
Test Suite 'Selected tests' passed at 2023-11-06 13:18:07.427
         Executed 1 test, with 0 failures (0 unexpected) in 0.004 (0.004) seconds

Without --privileged it crashes:

❯ docker run --rm -v $PWD:/code -w /code -it swift:5.9.1-jammy swift test --filter VsockAddressTest.testGetLocalCID
Building for debugging...
Build complete! (6.90s)
Test Suite 'Selected tests' started at 2023-11-06 13:18:43.133
Test Suite 'VsockAddressTest' started at 2023-11-06 13:18:43.134
Test Case 'VsockAddressTest.testGetLocalCID' started at 2023-11-06 13:18:43.134
NIOPosix/VsockAddress.swift:223: Fatal error: 'try!' expression unexpectedly raised an error: open(file:oFlag:): No such file or directory (errno: 2)
...[crash dump]...

This behaviour isn't new to 5.9.1, it happens in 5.9.0-jammy too.

I'll note however, that the crash I've pasted is different from yours. Mine is failing to open /dev/vsock. But yours is failing after performing the ioctl().

What I'm surprised about in both cases is that these tests are running. They have try XCTSkipUnless(System.supportsVsock), which checks that we can create a socket with AF_VSOCK. Clearly this is not enough of a guard.

On Linux, we can make that also check for the presence of /dev/vsock which would skip the test in my case above.

This is a bug I can make a patch for, but it's not your bug...

However, we need to dig a little deeper on your environment to work out what's going on, because it seems you do have /dev/vsock but IOCTL_VM_SOCKETS_GET_LOCAL_CID isn't getting the local CID.

simonjbeaumont commented 10 months ago

In @fabianfett's case, the following code is failing:

        var cid = Self.any.rawValue
        try Posix.ioctl(fd: fd, request: request, ptr: &cid)  // IOCTL_VM_SOCKETS_GET_LOCAL_CID
        precondition(cid != Self.any.rawValue)

Essentially this checks that, after a successful ioctl() call, that the address is not VMADDR_CID_ANY.

I've dug a little more on this and think that we've been too strict. Looking at some implementations...

All that to say... we probably shouldn't make any precondition on the result of IOCTL_VM_SOCKETS_GET_LOCAL_CID since it appears there's some places where it may intentionally be VMADDR_CID_ANY.

I am struggling to reproduce this locally in both a Linux VM and a Linux container, but I think the path forward here is a patch that does the following:

  1. Update the hasVsockSupport guard that conditionally runs the test to include the presence of /dev/vsock when on Linux.
  2. Remove the precondition that checks that the local CID as returned by the ioctl() is not VMADDR_CID_ANY.
simonjbeaumont commented 10 months ago

@fabianfett has provided me some information about his VM.

My VM (where I cannot reproduce the crash) is using different Vsock transport from his. This is mine...

$ lsmod | grep vsock
vmw_vsock_virtio_transport    24576  0
vmw_vsock_virtio_transport_common    53248  1 vmw_vsock_virtio_transport
vsock                  61440  2 vmw_vsock_virtio_transport_common,vmw_vsock_virtio_transport

This is @fabianfett's:

$ lsmod | grep vsock
vsock_loopback         16384  0
vmw_vsock_virtio_transport_common    40960  1 vsock_loopback
vmw_vsock_vmci_transport    32768  0
vsock                  49152  3 vmw_vsock_virtio_transport_common,vsock_loopback,vmw_vsock_vmci_transport
vmw_vmci               90112  1 vmw_vsock_vmci_transport

There's a notable difference of transport, which, based on the above comment could be the source of the different behaviour.

simonjbeaumont commented 10 months ago

@fabianfett would you mind trying out the patch here in your environment? https://github.com/apple/swift-nio/pull/2588