SwiftPackageIndex / SwiftPackageIndex-Server

The Swift Package Index is the place to find Swift packages!
https://swiftpackageindex.com
Apache License 2.0
538 stars 42 forks source link

`test_package_collections_owner` crashes in Xcode 16b5 when run with TSAN #3289

Closed finestructure closed 3 weeks ago

finestructure commented 1 month ago

CleanShot 2024-08-13 at 19 17 32@2x

finestructure commented 4 weeks ago

This is a TSAN issue:

❯ env DEVELOPER_DIR=/Applications/Xcode-16.0.0-Beta.5.app xcrun swift test --sanitize=thread --disable-automatic-resolution --filter ApiTests.test_package_collections_owner
...
Test Case '-[AppTests.ApiTests test_package_collections_owner]' started.
2024-08-14T08:30:44+0200 info codes.vapor.request : request-id=8FE86B25-4DD7-4E63-BF2F-8918F72F87B2 [Vapor] POST /api/package-collections
ThreadSanitizer:DEADLYSIGNAL
==517==ERROR: ThreadSanitizer: SEGV on unknown address 0x080206740eb0 (pc 0x0001033aad84 bp 0x00016d316b40 sp 0x00016d316b10 T17167653)
==517==The signal is caused by a READ memory access.
    #0 __tsan::MemoryAccess(__tsan::ThreadState*, unsigned long, unsigned long, unsigned long, unsigned long) <null>:116401536 (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x62d84)
    #1 OCSPNonce.init<A>(generator:) OCSPNonce.swift:34 (SPI-ServerPackageTests:arm64+0x5b59c48)
    #2 OCSPNonce.init() OCSPNonce.swift:30 (SPI-ServerPackageTests:arm64+0x5b59b58)
    #3 OCSPVerifierPolicy.Storage.queryAndVerifyCertificateStatus(for:responderURI:issuer:) OCSPPolicy.swift:344 (SPI-ServerPackageTests:arm64+0x5b68080)
    #4 swift::runJobInEstablishedExecutorContext(swift::Job*) <null>:104174304 (libswift_Concurrency.dylib:arm64e+0x4e2dc)

==517==Register values:
 x[0] = 0x0000000102bc4000   x[1] = 0xf235080206740eb0   x[2] = 0x000000000e873310   x[3] = 0x0000000000000001
 x[4] = 0x0000000000000000   x[5] = 0x0000000000000000   x[6] = 0x0000000000000000   x[7] = 0x0000000000000000
 x[8] = 0xf91a8001033a075c   x[9] = 0x0000000129661c4c  x[10] = 0x0000000000000000  x[11] = 0x000000000e873300
x[12] = 0x0000000000000010  x[13] = 0x0000000000000010  x[14] = 0x000000011f1cc5a0  x[15] = 0x0000000000000000
x[16] = 0x0000000185b50da4  x[17] = 0x00000001033e0b08  x[18] = 0x0000000000000000  x[19] = 0x0000000000000000
x[20] = 0xf91a8001033a075c  x[21] = 0x0000000129661c4c  x[22] = 0x0000000000000001  x[23] = 0x0000000102bc4000
x[24] = 0x0000000000000009  x[25] = 0x000000025d7af978  x[26] = 0x000000025d7af988  x[27] = 0x0000000000000000
x[28] = 0x000000016d3170e0     fp = 0x000000016d316b40     lr = 0x000000010337502c     sp = 0x000000016d316b10
ThreadSanitizer can not provide additional info.
SUMMARY: ThreadSanitizer: SEGV (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x62d84) in __tsan::MemoryAccess(__tsan::ThreadState*, unsigned long, unsigned long, unsigned long, unsigned long)+0x44
==517==ABORTING
error: Exited with unexpected signal code 6

Without TSAN the test runs and passes:

❯ env DEVELOPER_DIR=/Applications/Xcode-16.0.0-Beta.5.app xcrun swift test --disable-automatic-resolution --filter ApiTests.test_package_collections_owner
...
Test Case '-[AppTests.ApiTests test_package_collections_owner]' started.
2024-08-14T08:33:10+0200 info codes.vapor.request : request-id=BE37F21E-46EE-4534-A5C5-236FF00FAC05 [Vapor] POST /api/package-collections
Test Case '-[AppTests.ApiTests test_package_collections_owner]' passed (1.655 seconds).
Test Suite 'ApiTests' passed at 2024-08-14 08:33:11.434.
     Executed 1 test, with 0 failures (0 unexpected) in 1.655 (1.656) seconds
finestructure commented 4 weeks ago

Passes with Xcode 16b3:

❯ env DEVELOPER_DIR=/Applications/Xcode-16.0.0-Beta.3.app xcrun swift test --sanitize=thread --disable-automatic-resolution --filter ApiTests.test_package_collections_owner
...
Test Case '-[AppTests.ApiTests test_package_collections_owner]' started.
2024-08-14T08:36:15+0200 info codes.vapor.request : request-id=4C718819-848F-44C8-9672-265D1188A0E9 [Vapor] POST /api/package-collections
Test Case '-[AppTests.ApiTests test_package_collections_owner]' passed (1.881 seconds).
Test Suite 'ApiTests' passed at 2024-08-14 08:36:17.376.
     Executed 1 test, with 0 failures (0 unexpected) in 1.881 (1.881) seconds
finestructure commented 4 weeks ago

Passes on Linux:

❯ dsh registry.gitlab.com/finestructure/spi-base:74dc3374a9014924a3c0a6a55460570679b9dc1a92d17a31b8016aa652318b19
# bash
################################################################
#                                                              #
# Swift Nightly Docker Image                                   #
# Tag: swift-6.0-DEVELOPMENT-SNAPSHOT-2024-08-10-a             #
#                                                              #
################################################################
root@orbstack:/host# swift test --sanitize=thread --disable-automatic-resolution --filter ApiTests.test_package_collections_owner
...
Test Case 'ApiTests.test_package_collections_owner' started at 2024-08-14 07:07:43.758
2024-08-14T07:07:44+0000 info codes.vapor.request : request-id=A6286290-EBE5-4EBD-988E-FC33A2614DC7 [Vapor] POST /api/package-collections
Test Case 'ApiTests.test_package_collections_owner' passed (2.662 seconds)
finestructure commented 3 weeks ago

Fixed in Xcode 16b5:

❯ env DEVELOPER_DIR=/Applications/Xcode-16.0.0-Beta.6.app xcrun swift test --sanitize=thread --disable-automatic-resolution --filter ApiTests.test_package_collections_owner
...
Build complete! (29.97s)
Test Suite 'Selected tests' started at 2024-08-22 09:47:19.265.
Test Suite 'SPI-ServerPackageTests.xctest' started at 2024-08-22 09:47:19.267.
Test Suite 'ApiTests' started at 2024-08-22 09:47:19.267.
Test Case '-[AppTests.ApiTests test_package_collections_owner]' started.
2024-08-22T09:47:19+0200 info codes.vapor.request : request-id=43A33654-B7BB-4B62-BEE7-0138F84CFCBA [Vapor] POST /api/package-collections
Test Case '-[AppTests.ApiTests test_package_collections_owner]' passed (3.657 seconds).
Test Suite 'ApiTests' passed at 2024-08-22 09:47:22.924.
     Executed 1 test, with 0 failures (0 unexpected) in 3.657 (3.657) seconds
Test Suite 'SPI-ServerPackageTests.xctest' passed at 2024-08-22 09:47:22.924.
     Executed 1 test, with 0 failures (0 unexpected) in 3.657 (3.658) seconds
Test Suite 'Selected tests' passed at 2024-08-22 09:47:22.925.
     Executed 1 test, with 0 failures (0 unexpected) in 3.657 (3.659) seconds